Get data from other open excel sheet without using filename

mrmlee2209

New Member
Joined
Sep 14, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi All.

I'm doing daily gathering of data from multiple sources to a master spreadsheet.

Most of the daily data is emailed automatically each day.

For 3 out of 4 of the sheets I need, I've simply created a macro button. I open the excel attachment on the email, go to my master sheet, click the button and it selects the data from the attachment excel and paste-values into the master sheet. Simple.

However, for the fourth email attachment, the excel filename is always different, it appends the date to the file name. Hence, when I click the button I've created, it doesn't match the file name and faults.

Here's the script for it...


VBA Code:
Sub Get_Stark_Data()
'
' Get_Stark_Data Macro
'

'
    Windows("Meter-Sequential_1-Day_CSV-kWh_Electricity_Ending-06-09-2021.csv"). _
        Activate
    Range("I10:BD10").Select
    Selection.Copy
    Windows("Export Monitoring Data.xlsm").Activate
    Range("C18").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Windows("Meter-Sequential_1-Day_CSV-kWh_Electricity_Ending-06-09-2021.csv"). _
        Activate
    ActiveWindow.Close
End Sub

As you can see, the filename would be different for tomorrows data and the scrip would not work.

How can I amend the script to select the other open worksheet (only have 2 open at once) rather than using a specific filename? I was hoping replacing the date with wildcard* would work, but it didn't.

Many thanks for your help... manually copying and pasting this data was getting tedious. I'm 3/4 of the way there to help reduce that!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
?
VBA Code:
"Meter-Sequential_1-Day_CSV-kWh_Electricity_Ending-*.csv")
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub Get_Stark_Data()
'
' Get_Stark_Data Macro
'
   Dim Wbk As Workbook
   For Each Wbk In Workbooks
      If Wbk.Name Like "Meter-Sequential_1-Day_CSV-kWh_Electricity_Ending*" Then Exit Sub
   Next Wbk
      
    Wbk.Sheets(1).Range("I10:BD10").Copy
    Workbooks("Export Monitoring Data.xlsm").Range("C18").PasteSpecial xlPasteValues
    Wbk.Close
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub Get_Stark_Data()
'
' Get_Stark_Data Macro
'
   Dim Wbk As Workbook
   For Each Wbk In Workbooks
      If Wbk.Name Like "Meter-Sequential_1-Day_CSV-kWh_Electricity_Ending*" Then Exit Sub
   Next Wbk
     
    Wbk.Sheets(1).Range("I10:BD10").Copy
    Workbooks("Export Monitoring Data.xlsm").Range("C18").PasteSpecial xlPasteValues
    Wbk.Close
End Sub
Thanks Fluff...

Didn't quite work but lead me in the right direction. Ended up with:


VBA Code:
Sub Get_Stark_Data()
'
' Get_Stark_Data Macro
'

'
    Dim Wbk As Workbook
        
    For Each Wbk In Application.Workbooks
        If Wbk.Name Like "Meter-Sequential_1-Day_CSV-kWh_Electricity_Ending-*" Then
            Wbk.Activate
            ActiveSheet.Range("I10:BD10").Copy
            Workbooks("Export Monitoring Data.xlsm").Activate
            ActiveSheet.Range("C18:AX18").PasteSpecial xlPasteValues
            Wbk.Activate
            ActiveWindow.Close
        End If
    Next Wbk

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,961
Members
452,539
Latest member
delvey

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