我有两列数据,A 和 B。我想在 B 列中找到空白单元格,然后如果 A 也不是空白,则从 A 列中的相应单元格复制数据。
问问题
3468 次
3 回答
1
我会使用 SpecialCells:
Sub fillblanks()
Dim rngBlanks As Range
Dim rng As Range
Dim cl As Range
Set rng = ActiveSheet.UsedRange.Columns(2)
Set rngBlanks = rng.SpecialCells(xlCellTypeBlanks)
For Each cl In rngBlanks.Cells
With cl
If (.Value = "") And (.Offset(0, -1).Value <> "") Then
.Value = .Offset(0, -1).Value
End If
End With
Next
End Sub
于 2013-06-18T14:26:02.480 回答
1
Sub Sample2()
On Error Resume Next
With Columns("B").SpecialCells(xlCellTypeBlanks)
.FormulaR1C1 = "=RC[-1]"
.Value = .Value
End With
End Sub
如果 A 中的单元格为空白,这并不能完全按照您的要求,好像不会跳过空白单元格,这是因为我不明白为什么用另一个空白替换和空白会是一个问题。如果有的话,只需修改 .FormulaR1C1 = "=RC[-1]"
以考虑空白,就可以轻松解决问题。
于 2013-06-18T14:30:04.870 回答
1
不需要VBA。选择 ColumnB, HOME > Editing, Find & Select, Go To Special..., Select Blanks (only),
=
←</kbd>, Ctrl+Enter.
于 2015-09-12T02:05:04.363 回答