importing from multiple workbooks with different worksheet name

22newbie

New Member
Joined
Jun 11, 2022
Messages
13
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all,

I have a working code for pulling worksheet from multiple workbooks. However, I found out some of the worksheets are of different names.
All workbooks have 1 sheet in them which I am importing but they are all of different names. How do I go about doing it? My current code look something like this... thank you in advance
VBA Code:
hile strExtension <> ""
        Set srcWB = Workbooks.Open(strPath & strExtension)
        With srcWB.Sheets("Sheet2")
            LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            .Range("A2:D" & LastRow).Copy desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1, 0)
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Maybe, since you state that every workbook you are to pull from has only one sheet then you could try changing:
With srcWB.Sheets("Sheet2")
to:
With srcWB.ActiveSheet
 
Upvote 0
Solution
Maybe, since you state that every workbook you are to pull from has only one sheet then you could try changing:
With srcWB.Sheets("Sheet2")
to:
With srcWB.ActiveSheet
omg! worked like magic! Thank you!
 
Upvote 0
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,343
Members
449,155
Latest member
ravioli44

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