简体   繁体   English

VBA复制粘贴

[英]VBA copy pasting

I wrote a VBA which copy and paste data from one sheet to another. 我写了一个VBA,可以将数据从一张纸复制并粘贴到另一张纸。 The VBA only works for on row which data is in sheet2. VBA仅适用于数据在sheet2中的行。 I need the VBA to automatically go to the next row. 我需要VBA自动转到下一行。 It needs to do that until there is no data in the next row. 它需要这样做,直到下一行没有数据为止。 In the example down below it's already after 3 rows. 在下面的示例中,它已经排了3行。

data 数据

Sub goeie()
    With Sheets("A")

    'bord 2 verwijzingen
    .[C42].FormulaR1C1 = "=blad2!R[4]C[13]"
    .[D42].FormulaR1C1 = "=blad2!R[4]C[10]"
    .[E42].FormulaR1C1 = "=blad2!R[4]C[10]"
    .[F42].FormulaR1C1 = "=IF(blad2!R[4]C[11]=""S235"",235,355)"

    'bord 1 verwijzingen
    .[C43].FormulaR1C1 = "=blad2!R[3]C[9]"
    .[D43].FormulaR1C1 = "=blad2!R[3]C[6]"
    .[E43].FormulaR1C1 = "=blad2!R[3]C[6]"
    .[F43].FormulaR1C1 = "=IF(blad2!R[3]C[7]=""S235"",235,355)"

    'deur
    .[C56].FormulaR1C1 = "=blad2!R[-10]C[3]"
    .[D56].FormulaR1C1 = "=blad2!R[-10]C[1]"
    .[E56].FormulaR1C1 = "=blad2!R[-10]C[2]"
    .[F56].FormulaR1C1 = "=IF(blad2!R[3]C[2]=""V"",""X-as"",""Y-as"")"
    End With

    With Sheets("Blad2")
    .[R46].FormulaR1C1 = "=A!R[12]C[1]"
    End With

End Sub

you need to use Offset to do this 您需要使用“偏移”来执行此操作

example: 例:

     pasteSheet.Cells(pasteSheet.Rows.Count, 1).End(xlUp).Offset(1, 0).Value = .Value
     pasteSheet.Cells(pasteSheet.Rows.Count, 1).End(xlUp).Offset(0, 1).Value = .Value
     pasteSheet.Cells(pasteSheet.Rows.Count, 1).End(xlUp).Offset(0, 2).Value = .Value

I included multiple examples so that you know how to navigate between columns and rows :) Offset(rows,columns) 我提供了多个示例,以便您知道如何在列和行之间导航:)偏移量(行,列)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM