update in the name of the spreadsheet - macro will still pick up the data

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

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
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try:
Code:
With Wbk.Sheets("Report*")
 
Upvote 0
Try:
Code:
Dim ws As Worksheet
For Each ws In Sheets
    If ws.Name Like "Report*" Then
        LastRow = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Sht.Range("A2:AC" & LastRow).ClearContents
        ws.Range("A2:AC" & LastRow).Copy
        Sht.Range("A2").PasteSpecial xlPasteValues
    End If
Next ws
Keep in mind that the way you have written your code, LastRow refers to the "Report*" sheet and you are using that variable in both Sht and in the "Report*" sheet.
 
Upvote 0
It is always easier to help and test possible solutions if we could work with your actual file. Perhaps you could upload a copy of your two files to a free site such as www.box.com or www.dropbox.com. Once you do that, mark each file for 'Sharing' and you will be given a link to each file that you can post here. Include a detailed explanation of what you would like to do referring to specific cells and worksheets. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top