![](/img/trans.png)
[英]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.