[英]Excel VBA - If a cell in column B contains a value then column A equals “value” BUT do not overwrite existing column A data
[英]Excel VBA if Column B contains a value then copy that value to Column A do not overwrite existing Column A data
我现在有一些代码可以查看B列,并使用预定值(代码片段中的“ ANY VALUE”更新A列),但是我要寻找的是能够复制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
我想转一下:
到这个:
在此先感谢您的协助!
您可以使用SpecialCells()
来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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.