Pull data from multiple files with multiple unknown sheet names in each

cjouban

New Member
Joined
Jan 21, 2014
Messages
23
Sorry if I missed a thread that solves this. I am trying to copy same cell in multiple workbooks with multiple sheets to a new workbook. I've found examples that require a sheet name but I have know idea what each sheet is named. The macro needs to work it's way through all files in a folder and each sheet in the file pasting the results in a new workbook. Thanks in advance for any help.
 
When you get the error, click the debug button & it will highlight the problem line. Which line gets highlighted? Also What is the error message?
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Run-time error 424
Object required

1574199768352.png
 
Upvote 0
I don't see how you get that error on that line.
Did you run the macro & then click the debug button?
 
Upvote 0
I changed the error trapping to "Break on All Errors". Now I get the debug button. It wasn't showing up before.
The error is on this line
NxtRw = destws.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
 
Upvote 0
Oops, typo on my part, it should be
Rich (BB code):
NxtRw = desWS.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
 
Upvote 0
Success!!! Thanks again for your help.
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim desWS As Worksheet, srcWB As Workbook, ws As Worksheet
    Set desWS = ThisWorkbook.Sheets("Sheet1")
    Dim FolderName As String
    Dim NxtRw As Long
   NxtRw = desWS.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
    With Application.FileDialog(msoFileDialogFolderPicker)
       .AllowMultiSelect = False
       .Show
       FolderName = .SelectedItems(1) & "\"
    End With
    ChDir FolderName
    strExtension = Dir("*.xlsx")
    Do While strExtension <> ""
        Set srcWB = Workbooks.Open(FolderName & strExtension)
        For Each ws In Sheets
             With ws
                desWS.Cells(NxtRw, "A") = .Range("A1")
                desWS.Cells(NxtRw, "B") = .Range("A2")
                desWS.Cells(NxtRw, "C") = .Range("A3")
                desWS.Cells(NxtRw, "D") = .Range("A4")
                NxtRw = NxtRw + 1
            End With
        Next ws
        srcWB.Close False
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,726
Members
449,093
Latest member
Mnur

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