我现在有一些代码会查看B列,并会更新A列的预定值(" ANY VALUE"来自我的代码片段),但我要找的是能够复制B列中的内容并将其粘贴到A列中。这是我到目前为止的代码:
Sub Copy_And_Paste_Column_Values_Into_Column_1()
On Error Resume Next
Dim ws As Worksheet
Dim lRow As Long
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
lRow = .Range("B" & .Rows.Count).End(xlUp).Row
.Range("A1:A" & lRow).SpecialCells(xlCellTypeBlanks).Formula = "=If(B1<>"""",""ANY VALUE"","""")"
.Range("A1:A" & lRow).Value = .Range("A1:A" & lRow).Value
End With
End Sub
我想转此:
进入这个:
提前感谢您的帮助!
答案 0 :(得分:1)
您可以使用SpecialCells()
:
Sub copy_data_to_blanks()
Dim rng As Range
Set rng = Range("A1:A3") ' Change this as necessary.
rng.Cells.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=rc[1]"
rng.Value = rng.Value ' This effectively removes the formulas, just by overwriting the range with the actual values.
End Sub