[英]copy from column A (Sheet1) to Column B (Sheet2) below previous data of column B
How to copy data from column A (Sheet1) to column B (Sheet2) without modifying previous data on colunm B? 如何将数据从A列(Sheet1)复制到B列(Sheet2),而又不修改列B上的先前数据? Thank you in Advance.
先感谢您。
Here's a generic answer that does not replace the cells but looks for the next empty ones. 这是一个通用答案,它不会替换单元格,而是寻找下一个空单元格。 I've tried to put comments in that will help understand it.
我试图在其中添加评论将有助于理解它。
Sub CopySheet1toSheet2()
Dim CurrRow As Integer
Dim CurrCol As Integer
Dim TargetRow As Integer
Dim TargetCol As Integer
Dim Sheet1 As String
Dim Sheet2 As String
Sheet1 = "Sheet1" ' name to your source sheet name
Sheet2 = "Sheet2" ' change to your target sheet name
CurrRow = 1
CurrCol = 1 ' This is column A
TargetRow = 1
TargetCol = 2 ' This is column B
' Cycle through all rows in Col A until empty field reached
While Sheets(Sheet1).Cells(CurrRow, CurrCol) <> ""
' See if there's a value in column B in the same row - if so, go to the next row
While Sheets(Sheet2).Cells(TargetRow, TargetCol) <> ""
TargetRow = TargetRow + 1
Wend
' Copy the value from the source to the target
Sheets(Sheet2).Cells(TargetRow, TargetCol) = Sheets(Sheet1).Cells(CurrRow, CurrCol)
' Move to the next source and target rows
CurrRow = CurrRow + 1
TargetRow = TargetRow + 1
Wend
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.