This is a modified script from this forum and it serves it purpose well. But I the issue I am having now is that currently the script copies a bunch of values from a DIR and paste it in the main worksheet.
But in this the DIR the tab names of the sheet varies so the code breaks when it encounters this change. So lets say I have 100 excel files in there, it scans through and copies and on lets say the 7th file which is identical to other files, but the tab name is diff. It stops working ending with a script error:
I tried referencing it by code name instead of sheet name. So where it says:
I changed it to:
And it looks like it is doing something. But the entries keep coming back blank. Any thoughts how I can achieve this?
And the tab name varies between just three types, Either Commission or USD Commission or AUD Commission
Thank you again!
But in this the DIR the tab names of the sheet varies so the code breaks when it encounters this change. So lets say I have 100 excel files in there, it scans through and copies and on lets say the 7th file which is identical to other files, but the tab name is diff. It stops working ending with a script error:
Code:
Sub CopyRange()
Application.ScreenUpdating = False
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Set wkbDest = ThisWorkbook
Const strPath As String = "C:\Users\xxx\1-DUMP2\"
ChDir strPath
strExtension = Dir("*.xls*")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
With wkbSource
.Sheets("Commission").Range("C22").Copy
wkbDest.Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats, _
Operation:=xlNone, SkipBlanks:=True, Transpose:=False
.Close savechanges:=False
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.CutCopyMode = False
End Sub
I tried referencing it by code name instead of sheet name. So where it says:
Code:
.Sheets("Commission").Range("C22").Copy
I changed it to:
Code:
Sheet1.Range("C22").Copy
And the tab name varies between just three types, Either Commission or USD Commission or AUD Commission
Thank you again!
Last edited: