[英]VBA Macro that transfer data from 1 excel to another
I am new to excel macro vba please help.... My below code is to transfer data from 1 excel to another.我是 excel 宏 vba 的新手,请帮忙.... 我下面的代码是将数据从 1 个 excel 传输到另一个。 However, when I execute the macro it transfers only 1 row ie A2 and B2 cell values into another excel.但是,当我执行宏时,它仅将 1 行(即 A2 和 B2 单元格值)传输到另一个 Excel 中。
My VBA code....我的 VBA 代码....
Private Sub CommandButton1_Click()
Dim InvoiceNumber As String
Dim ForwarderCode As String
Dim wb As Workbook
Worksheets("SampleFile").Select
InvoiceNumber = Range("A2")
Worksheets("SampleFile").Select
ForwarderCode = Range("B2")
Set wb = Workbooks.Open("C:DestinationPath.xlsm")
Worksheets("Sheet1").Select
Worksheets("Sheet1").Range("A2").Select
RowCount = Worksheets("Sheet1").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet1").Range("A1")
.Offset(RowCount, 0) = InvoiceNumber
.Offset(RowCount, 1) = ForwarderCode
End With
wb.Save
End Sub
Please help it should transfer the entire data present in column A and B....请帮助它应该传输 A 列和 B 列中存在的全部数据....
If you want copying from A1 to C last filled cell, try the next code, please:如果您想从 A1 复制到 C 最后填充的单元格,请尝试下一个代码,请:
Private Sub CommandButton1_Click___()
Dim shSF As Worksheet, sh1 As Worksheet
Dim wb As Workbook, lastRow As Long
Set shSF = Worksheets("SampleFile")
lastRow = shSF.Range("A" & Rows.count).End(xlUp).row
Set wb = Workbooks.Open("C:DestinationPath.xlsm")
Set sh1 = wb.Worksheets("Sheet1")
shSF.Range("A1:C" & lastRow).Copy Destination:=sh1.Range("A1")
wb.Save
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.