[英]Copy paste specific cell values from one work sheet to another based on a specific criteria
[英]Copy Cell values from One Sheet to Another on certain criteria with the paste
您好,我正在嘗試制作一個宏,該宏將從Sheet1的所有200個值從A1復制到A2,並將其粘貼到Sheet 2中,但是粘貼操作應將它們分別粘貼在2列和3行空間中。
Sheet1(A1) => Sheet2(A1)
Sheet1(A2) => Sheet2(B1)
Sheet1(A3) => Sheet2(A5)
Sheet1(A4) => Sheet2(B5)
Sheet1(A5) => Sheet2(A9)
Sheet1(A6) => Sheet2(B9)
如您所見,間隔是+3個單元格。 到目前為止,我所做的是復制單個單元格,並且需要任何幫助或建議如何從上方進行復制過程。
Sub CopySelection()
Dim xlSel As Excel.Range
Set xlSel = Excel.Application.Selection
For i = 0 To 200
xlSel.copy Excel.Application.Sheets("Sheet2").Range("A1")
Next i
End Sub
任何幫助都將受到歡迎。
您可以這樣做:
Dim Destination_Row As Integer
Destination_Row = 1
For Origin_Row = 1 To 200 Step 2
Sheet2.Cells(Destination_Row, 1).Value = Sheet1.Cells(Origin_Row, 1).Value
Sheet2.Cells(Destination_Row, 2).Value = Sheet1.Cells(Origin_Row + 1, 1).Value
Destination_Row = Destination_Row + 4
Next
Cells
屬性返回指定Row
和Column
的Range
。 For
循環的每一步都加2以從Sheet1
獲取值,並將4加至Destination_Row
以將值粘貼到Sheet2
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.