我想将数据粘贴到从另一个工作簿保存到特定单元格的数组中。在2个匹配项中选择了目标单元格:
有了此单元格信息,我想将数据粘贴到该字段。这是一个循环,因为我必须将9个数据输入到相应的单元格中。
Sub copyData()
Dim source As Workbook
Dim Machine(1 To 9, 1 To 2)
Dim r As Byte, c As Byte
Dim day As Byte
Dim rowCode As Long
Dim colmnDay As Long
Const StartRow As Long = 6
Const StartColumn As Long = 1
Set source = Workbooks.Open("C:\Users\Sabareesh\Desktop\MONTH_DATA.xlsx", True, True)
day = source.Worksheets("day 1").Range("W20").Value
For r = 1 To 9
For c = 1 To 2
Machine(r, c) = source.Worksheets("day 1").Cells(r + StartRow, c + StartColumn).Value
Next c
Next r
ThisWorkbook.Activate
For r = 1 To 9
For c = 1 To 2
colmnDay = WorksheetFunction.Match(day, Worksheets("sheet1").Range("F1:J5"), 0)
rowCode = WorksheetFunction.Match(Machine(r, 1), Worksheets("sheet1").Range("E2:E9"), 0)
Worksheets("sheet1").Cells(rowCode, colmnDay).Value = Machine(r, 2)
'Let row1 = "A" & r
'Let row2 = "B" & r
'Worksheets("sheet1").Range(row1).Value = Machine(r, 1)
'Worksheets("sheet1").Range(row2).Value = Machine(r, 2)
Next c
Next r
Workbooks("MONTH_DATA.xlsx").Close SaveChanges:=False
End Sub
它确实:通过打开工作簿MONTH_DATA,成功存储了这些变量“ day,Machine(代码(值,值)”。 VBA正在从另一个工作簿运行。
预期结果:match()需要获取匹配代码和日期的行和列位置。有了该单元格信息,我可以将值粘贴到其中。
我遇到错误
“无法获取WorksheetFunction类的Match属性”
在线
rowCode = WorksheetFunction.Match(Machine(r, 1), Worksheets("sheet1").Range("E2:E9"), 0)