列Bの以前のデータを変更せずに、列A(Sheet1)から列B(Sheet2)にデータをコピーするにはどうすればよいですか?前もって感謝します。
質問する
1299 次
1 に答える
1
これは、セルを置き換えるのではなく、次の空のセルを探す一般的な答えです。私はそれを理解するのに役立つコメントを入れようとしました。
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
于 2013-03-09T21:22:35.973 に答える