有条件地从上面的单元格中填充空白行
Filling Blank Rows from Cells Above Conditionally
我最初使用了一些脚本,其中工作表中前 3 列数据的空白行是从前一行填充的。脚本是:
Dim cell As Range, SearchRange As Range
On Error Resume Next
Set SearchRange = Columns("A:C").SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If Not SearchRange Is Nothing Then
For Each cell In SearchRange
If cell.row > 1 Then cell = cell.Offset(-1, 0).Value
Next cell
End If
虽然这对于那些列之间的空白行来说没问题,但我有一个问题,即空白位于我不想填充的 D 列中的文本旁边。我试过类似的东西:
If Not Like "*FUEL*" Or Like "ACCOUNTS*"
但我在条件语句中使用 this 时遇到语法问题。我粘贴的片段会有意义......我希望。我只想填写 D 列中 Jacqui 一词旁边的行,而不是 Fuel 或 Accounts。注意。 Jacqui这个词不是一成不变的。
Excel Sample
使用 cell.row 引用 D 列。
Dim cell As Range, SearchRange As Range
On Error Resume Next
Set SearchRange = Columns("A:C").SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If Not SearchRange Is Nothing Then
For Each cell In SearchRange
If cell.Row > 1 And Not (Cells(cell.Row, "D") Like "ACCOUNTS*" Or Cells(cell.Row, "D") Like "FUEL*") Then _
cell = cell.Offset(-1, 0).Value
Next cell
End If
我最初使用了一些脚本,其中工作表中前 3 列数据的空白行是从前一行填充的。脚本是:
Dim cell As Range, SearchRange As Range
On Error Resume Next
Set SearchRange = Columns("A:C").SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If Not SearchRange Is Nothing Then
For Each cell In SearchRange
If cell.row > 1 Then cell = cell.Offset(-1, 0).Value
Next cell
End If
虽然这对于那些列之间的空白行来说没问题,但我有一个问题,即空白位于我不想填充的 D 列中的文本旁边。我试过类似的东西:
If Not Like "*FUEL*" Or Like "ACCOUNTS*"
但我在条件语句中使用 this 时遇到语法问题。我粘贴的片段会有意义......我希望。我只想填写 D 列中 Jacqui 一词旁边的行,而不是 Fuel 或 Accounts。注意。 Jacqui这个词不是一成不变的。
Excel Sample
使用 cell.row 引用 D 列。
Dim cell As Range, SearchRange As Range
On Error Resume Next
Set SearchRange = Columns("A:C").SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If Not SearchRange Is Nothing Then
For Each cell In SearchRange
If cell.Row > 1 And Not (Cells(cell.Row, "D") Like "ACCOUNTS*" Or Cells(cell.Row, "D") Like "FUEL*") Then _
cell = cell.Offset(-1, 0).Value
Next cell
End If