Hi All,
I'm pretty new to VBA, this is my also my first time posting on here. Hoping somebody can help me tweak my code;
The code loops through all the files in a folder to copy data from a sheet called ("P&L 2019 - UK GAAP") into one workbook.
The issue that I'm having is that, a couple of the workbooks have not named the sheet ("P&L 2019 - UK GAAP")......
The sheet name will start with P&L so I'm looking for some kind of wildcard, or partial match lookup...
But there is another sheet called "P&L 2019 - US GAAP" withing the workbook, which I want to avoid picking up.
Any help on this would be great!
Sub Template_Consol()
Dim myfile As String
Dim q As Long
q = 1
Dim filepath As String
Dim noWbs As Byte
'This picks up the number of workbooks from the input cell
noWbs = Sheets("inputs for Macro").Range("b3")
'Pick filepath from cell B3 in tab called "Inputs for Macro"
filepath = Sheets("Inputs for Macro").Range("b2")
'Add backslash to the end of the filepath name so that we have the correct syntax in order to concatenate the file name onto the end of this
If Right(filepath, 1) <> "" Then filepath = filepath & ""
Application.ScreenUpdating = False
myfile = Dir(filepath)
Do While Len(myfile) > 0
Workbooks.Open (filepath & myfile)
'Update Sheet name if I want to pull form another sheet
Worksheets("P&L 2019 - UK GAAP").Activate
ActiveSheet.UsedRange.Copy
ActiveWorkbook.Close Save = False
'This should stop excel from asking me about large amount of data on clipboard
Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
Sheets(q).Select
ActiveSheet.Paste Destination:=Worksheets(q).Range("A1")
Application.CutCopyMode = False
q = q + 1
'Number of files is pulled from the input sheet in this workbook
If q > noWbs + 1 Then
Exit Sub
End If
myfile = Dir
Loop
ActiveWorkbook.Save
Application.ScreenUpdating = True
End Sub
I'm pretty new to VBA, this is my also my first time posting on here. Hoping somebody can help me tweak my code;
The code loops through all the files in a folder to copy data from a sheet called ("P&L 2019 - UK GAAP") into one workbook.
The issue that I'm having is that, a couple of the workbooks have not named the sheet ("P&L 2019 - UK GAAP")......
The sheet name will start with P&L so I'm looking for some kind of wildcard, or partial match lookup...
But there is another sheet called "P&L 2019 - US GAAP" withing the workbook, which I want to avoid picking up.
Any help on this would be great!
Sub Template_Consol()
Dim myfile As String
Dim q As Long
q = 1
Dim filepath As String
Dim noWbs As Byte
'This picks up the number of workbooks from the input cell
noWbs = Sheets("inputs for Macro").Range("b3")
'Pick filepath from cell B3 in tab called "Inputs for Macro"
filepath = Sheets("Inputs for Macro").Range("b2")
'Add backslash to the end of the filepath name so that we have the correct syntax in order to concatenate the file name onto the end of this
If Right(filepath, 1) <> "" Then filepath = filepath & ""
Application.ScreenUpdating = False
myfile = Dir(filepath)
Do While Len(myfile) > 0
Workbooks.Open (filepath & myfile)
'Update Sheet name if I want to pull form another sheet
Worksheets("P&L 2019 - UK GAAP").Activate
ActiveSheet.UsedRange.Copy
ActiveWorkbook.Close Save = False
'This should stop excel from asking me about large amount of data on clipboard
Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
Sheets(q).Select
ActiveSheet.Paste Destination:=Worksheets(q).Range("A1")
Application.CutCopyMode = False
q = q + 1
'Number of files is pulled from the input sheet in this workbook
If q > noWbs + 1 Then
Exit Sub
End If
myfile = Dir
Loop
ActiveWorkbook.Save
Application.ScreenUpdating = True
End Sub