I'm trying to copy a few columns of data from one excel file to another. I've tried debugging and I get the Run-Time Error 424: Object required on the line that opens the workbook - the other excel file does open with this code and then the error pops up.
Sub CreateMatDump()
Dim DumpFile As Workbook 'SAP Material Dump File
Dim NRows As Long
Dim SAPNum As Variant, MatType As Variant, MatGroup As Variant, UOM As Variant, MPN As Variant, MatDesc As Variant
'Count rows
NRows = Cells(Rows.Count, 14).End(xlUp).Row
'Copy values to arrays
SAPNum = Range(Cells(3, 2), Cells(NRows, 2)).Value
MatType = Range(Cells(3, 6), Cells(NRows, 6)).Value
MatGroup = Range(Cells(3, 11), Cells(NRows, 11)).Value
UOM = Range(Cells(3, 10), Cells(NRows, 10)).Value
MPN = Range(Cells(3, 14), Cells(NRows, 14)).Value
MatDesc = Range(Cells(3, 9), Cells(NRows, 9)).Value
'Open SAP Material Dump File
Set DumpFile = Workbooks.Open(Filename:="R:\BURNABY\SAP Templates (Parts Upload & Batch PR Entry)\SAP Material Dump - Test.xlsx")
'Print arrays to SAP Material Dump File
DumpFile.Sheets("Sheet1").Range("A2").Resize(NRows, 1).Value = SAPNum.Value
DumpFile.Sheets("Sheet1").Range("B2").Resize(NRows, 1).Value = MatType.Value
DumpFile.Sheets("Sheet1").Range("C2").Resize(NRows, 1).Value = MatGroup.Value
DumpFile.Sheets("Sheet1").Range("D2").Resize(NRows, 1).Value = UOM.Value
DumpFile.Sheets("Sheet1").Range("E2").Resize(NRows, 1).Value = MPN.Value
DumpFile.Sheets("Sheet1").Range("F2").Resize(NRows, 1).Value = MatDesc.Value
End Sub
Valueproperty. Likewise for the other variables. Just remove the.Value. Note also that your ranges aren't the same size. you're picking up from NRows-2 cells and setting the values into NRows cells - Tim Williams