Hello,
I have created a macro that copies data from a template and then opens the file on a shared drive, pastes the data on the next available row in said file, and then saves and closes the file and returns back to the original template. I have this macro working on 5 out of 7 computers. Two computers are getting the run-time error 9: Subscript out of range and I am not sure how to fix it. This error occurs at Set NextRow = Workbooks(DataCollection.Sheets(Sheet1).Range(A2).End(xlUp.Offset(1,0). AE2s value is a function that changes depending on who uses the file as the referenced drive may use a different drive letter depending on how it was configured on the persons PC. Additionally, if anyone sees any room for efficiencies, please do comment below. The macro does run in approx. 2 seconds when accessed from the U.S., but takes longer overseas. Below is the code:
Sub CopyData()
Dim Wb As Workbook
Set Wb1 = ActiveWorkbook
Set Wb1 = ThisWorkbook
Dim wbName As String
Dim NextRow As Range
Dim NextRow2 As Range
Application.ScreenUpdating = False
Set Wb = Workbooks.Open(Range("AE2").Value)
wbName = Wb.Name
Set NextRow = Workbooks("DataCollection").Sheets("Sheet1").Range("A2").End(xlUp).Offset(1, 0)
ThisWorkbook.Sheets("CData").Activate
Sheets("CData").Range("A2:GR2").Copy
NextRow.PasteSpecial (xlValues)
Set NextRow2 = Workbooks("DataCollection").Sheets("Sheet1").Range("A65536").End(xlUp).Offset(1, 0)
Debug.Print NextRow2.Address
Sheets("CData").Range("A2:GR2").Copy
NextRow2.PasteSpecial (xlValues)
Application.CutCopyMode = False
Wb.Save
Wb.Close
Application.ScreenUpdating = True
End Sub
I greatly appreciate the help! Thank you!
I have created a macro that copies data from a template and then opens the file on a shared drive, pastes the data on the next available row in said file, and then saves and closes the file and returns back to the original template. I have this macro working on 5 out of 7 computers. Two computers are getting the run-time error 9: Subscript out of range and I am not sure how to fix it. This error occurs at Set NextRow = Workbooks(DataCollection.Sheets(Sheet1).Range(A2).End(xlUp.Offset(1,0). AE2s value is a function that changes depending on who uses the file as the referenced drive may use a different drive letter depending on how it was configured on the persons PC. Additionally, if anyone sees any room for efficiencies, please do comment below. The macro does run in approx. 2 seconds when accessed from the U.S., but takes longer overseas. Below is the code:
Sub CopyData()
Dim Wb As Workbook
Set Wb1 = ActiveWorkbook
Set Wb1 = ThisWorkbook
Dim wbName As String
Dim NextRow As Range
Dim NextRow2 As Range
Application.ScreenUpdating = False
Set Wb = Workbooks.Open(Range("AE2").Value)
wbName = Wb.Name
Set NextRow = Workbooks("DataCollection").Sheets("Sheet1").Range("A2").End(xlUp).Offset(1, 0)
ThisWorkbook.Sheets("CData").Activate
Sheets("CData").Range("A2:GR2").Copy
NextRow.PasteSpecial (xlValues)
Set NextRow2 = Workbooks("DataCollection").Sheets("Sheet1").Range("A65536").End(xlUp).Offset(1, 0)
Debug.Print NextRow2.Address
Sheets("CData").Range("A2:GR2").Copy
NextRow2.PasteSpecial (xlValues)
Application.CutCopyMode = False
Wb.Save
Wb.Close
Application.ScreenUpdating = True
End Sub
I greatly appreciate the help! Thank you!