9DravenAlpha
New Member
- Joined
- Nov 28, 2019
- Messages
- 8
- Office Version
- 365
- 2019
- 2016
- 2013
- Platform
- Windows
Hi,
I have three workbooks located in a directory on my desktop. The master workbook is called MyCopyCode and it has a tab called Combo that I am trying to pull data in from two other source workbooks which are located in the same directory. In each of the source workbooks, the data is located on a tab called DayTab, and the data starts on row 2 and ranges from Columns A to AO. The source workbooks are updated each day so the row changes dynamically. So each day I have to run the code to pull in the data.
When I run the code, it copies the first source workbook data perfectly. When it loops to the second source workbook I get a subscript out of error #9. The code below shows in bold letters the line of code that is the issue. I am fairly new to excel vba and I have searched previous posts here/online but still can't narrow down the issue. I am new to this forum and its my first post.
I have three workbooks located in a directory on my desktop. The master workbook is called MyCopyCode and it has a tab called Combo that I am trying to pull data in from two other source workbooks which are located in the same directory. In each of the source workbooks, the data is located on a tab called DayTab, and the data starts on row 2 and ranges from Columns A to AO. The source workbooks are updated each day so the row changes dynamically. So each day I have to run the code to pull in the data.
When I run the code, it copies the first source workbook data perfectly. When it loops to the second source workbook I get a subscript out of error #9. The code below shows in bold letters the line of code that is the issue. I am fairly new to excel vba and I have searched previous posts here/online but still can't narrow down the issue. I am new to this forum and its my first post.
Rich (BB code):
Sub CopyRange()
Application.ScreenUpdating = False
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Set wkbDest = ThisWorkbook
Const strPath As String = "C:\Users\user\Desktop\Labor\"
ChDir strPath
strExtension = Dir("*.xls*")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
With wkbSource
.Sheets("DayTab").Range("A2:AO" & Range("A" & Rows.Count).End(xlUp).Row).Copy wkbDest.Sheets("Combo").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
'.Sheets("Combo").Range("D:D").Select
'Selection.NumberFormat = "mm/dd/yyyy"
.Close savechanges:=False
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: