Jeffreyxx01
Board Regular
- Joined
- Oct 23, 2017
- Messages
- 156
Hello guys,
is it possible to have an automatic update in the code that will find the name of the spreadsheet as for example when I pull the data from different workbook finding the report as it is now, but assuming the report is called now: Report (1)
is it possible to have the macro taking the report even if the name is not specific to report but can have it like Report (x)
X would be for the number in the bracket,
Thanks for the help
is it possible to have an automatic update in the code that will find the name of the spreadsheet as for example when I pull the data from different workbook finding the report as it is now, but assuming the report is called now: Report (1)
is it possible to have the macro taking the report even if the name is not specific to report but can have it like Report (x)
X would be for the number in the bracket,
Thanks for the help
Code:
Sub PullDataWB()
Dim Wbk As Workbook
Dim Sht As Worksheet
Dim Usdrws As Long
Dim LastRow As Long
Application.ScreenUpdating = False
Set Sht = ActiveWorkbook.Sheets("Pipeline Worker")
ChDrive "W:"
ChDir "W:\Insights Team\ALL ACADEMIC\Reporting\Weekly RAM\Pathways\RawData"
Fname = Application.GetOpenFilename(FileFilter:="xls Files (*.xls*), *.xls*", Title:="Select a file", MultiSelect:=False)
If Fname = "False" Then
MsgBox "no file selected"
Exit Sub
Else
Set Wbk = Workbooks.Open(Fname)
[COLOR=#ff0000] With Wbk.Sheets("Report") >>>>> For example having ("Report (1)")[/COLOR]
LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Sht.Range("A2:AC" & LastRow).ClearContents
.Range("A2:AC" & LastRow).Copy
Sht.Range("A2").PasteSpecial xlPasteValues
End With
Application.DisplayAlerts = False
Wbk.Close , False
Application.DisplayAlerts = True
Usdrws = Sht.Range("AC" & Rows.Count).End(xlUp).Row
Sht.Range("AD2:CE" & Usdrws).FillDown
End If
End Sub