如何将特定列中的所有空白replace为指定的string?

我正在使用下面的VBA代码,总结了一些调查结果:

Sub Main() ReplaceBlanks Multi_FindReplace End Sub Sub ReplaceBlanks() Dim ws As Worksheet Dim lastrow As Long Dim rng As Range Set ws = Sheets("Refined") lastrow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row For i = 2 To lastrow If WorksheetFunction.CountA(ws.Range(ws.Cells(i, 17), ws.Cells(i, 21))) = 0 Then If Not rng Is Nothing Then Set rng = Union(ws.Cells(i, 1), rng) Else Set rng = ws.Cells(i, 1) End If End If Next i rng.EntireRow.Delete End Sub Sub Multi_FindReplace() 'PURPOSE: Find & Replace a list of text/values throughout entire workbook 'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault Dim fndList As Variant Dim rplcList As Variant Dim x As Long fndList = Array("Mostly satisfied", "Completely satisfied", "N/A", "Not at all satisfied") rplcList = Array("Satisfied", "Satisfied", "Satisfied", "Not satisfied") Set sht = ActiveWorkbook.Sheets("Refined") 'Loop through each item in Array lists For x = LBound(fndList) To UBound(fndList) 'Loop through each worksheet in ActiveWorkbook sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _ LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _ SearchFormat:=False, ReplaceFormat:=False Next x End Sub 

此代码会生成仅显示“满意”或“不满意”短语的输出。 下图显示了它的外观:

在这里输入图像说明

然而,当它结束时,它也显示了一些空白单元格,我也想说“满意”(但是我们只想在删除空白行后调用答复者完全没有回答任何问题,这是完成的已经由“ReplaceBlanks”子function)。

我想要关注的空白单元格仅仅是那些在Q3到U3列,然后是W3到Z3,最后是AB3到AC3的列(即我不知道这些列中将有多less行,但至less从第3行开始。)

我不知道如何只关注这三组列,但我在第一组上尝试了下面的代码:

 Sub dural() Dim r As Range, LastRow As Long LastRow = Cells(Rows.Count, 2).End(xlUp).Row For Each r In Range("Q3:U19" & LastRow) If r.Text = "" Then r.Value = "Satisfied" Next r End Sub 

但是这一个把“满意”放在我需要的小组下面的一千行!

任何提示赞赏,谢谢

尝试这个:

 Sub dural() With Sheets("Refined") Intersect(.UsedRange, .Range("Q:U, W:Z, AB:AC")).SpecialCells(xlCellTypeBlanks).Value = "Satisfied" End With End Sub 

顺便说一句: "Q3:U19" & LastRow必将返回一些“Q3:Q19xxx”地址,xxx等于LastRow …