Hi
I have a file where I import data, but the person keeps on changing the Sheet name / front of house name.
So I'd like to use the code name / back of house name of the Sheet, when importing the data.
Does anyone know how I can use the code name / back of house name instead of the Sheet name in the code below, please?
So I want to change this: Worksheets("Sheet1").Select so that it refers to the name in the VB editor. Sometimes the front of house name is called "Sheet1" and other times it's called "Main" etc.
I have a file where I import data, but the person keeps on changing the Sheet name / front of house name.
So I'd like to use the code name / back of house name of the Sheet, when importing the data.
Does anyone know how I can use the code name / back of house name instead of the Sheet name in the code below, please?
So I want to change this: Worksheets("Sheet1").Select so that it refers to the name in the VB editor. Sometimes the front of house name is called "Sheet1" and other times it's called "Main" etc.
VBA Code:
Sub GetData()
Dim fd As FileDialog
Dim filewaschosen As Boolean
Dim ReportP As Workbook
Dim iWBP As Workbook
Set ReportP = ActiveWorkbook
Set fd = Application.FileDialog(msoFileDialogOpen)
fd.Filters.Clear
fd.Filters.Add "Custom Excel Files", "*.xlsx, *.xlsm, *.xls"
fd.AllowMultiSelect = False
fd.InitialFileName = Environ("UserProfile") & "\Main Folder"
filewaschosen = fd.Show
fd.Execute
Set iWBP = ActiveWorkbook
'Get data from file
Worksheets("Sheet1").Select
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Range("A1:AE" & lastrow).Copy