Copying data from one workbook to anotherworkbook

Natsha

New Member
Joined
May 20, 2021
Messages
44
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. Windows
I need to create an macro, firstly-where I can pick any folder data,secondly the folders I am gonna pick has only 1 to 5 files not more than that,it varies some time like 1 to 4 but will not exist more than 5, each files sheet 1 name is different and all workbook has only one sheet, i need all the sheet 1 in all workbook should be pasted into macro workbook like sheet 1,sheet 2 ,sheet3... accordingly

Kindly help,I tried so many time but couldn't. I am not that much into macros.
 
Hi mumps,

Sorry I couldn't find anything, the code is working great can you,I just need all the workbooks to be pasted in one sheet that is sheet 2 of macro workbook.

Can you help again
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try:
VBA Code:
Sub CopySheets()
    Application.ScreenUpdating = False
    Dim wkbDest As Workbook, wkbSource As Workbook, FolderName As String
    Set wkbDest = ThisWorkbook
    With Application.FileDialog(msoFileDialogFolderPicker)
       .AllowMultiSelect = False
       .Show
       FolderName = .SelectedItems(1) & "\"
    End With
    ChDir FolderName
    strExtension = Dir("*.xls*")
    Do While strExtension <> ""
        Set wkbSource = Workbooks.Open(FolderName & strExtension)
        With wkbSource
            .Sheets(1).UsedRange.Offset(1).Copy Sheets(2).Cells(Sheets(2).Rows.Count, "A").End(xlUp).Offset(1)
            .Close False
        End With
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi mumps,

I am getting error on the below code

Sheets(1).UsedRange.Offset(1).Copy Sheets(2).Cells(Sheets(2).Rows.Count, "A").End(xlUp).Offset(1)

Description: I need all the workbooks data to be pasted in sheet-2 of macro workbook one by one below and I want the first row in all those workbooks to be removed.
 
Upvote 0
What is the error message when you click "Debug"? What is the name of the sheet 2?
 
Upvote 0
The error message is runtime error 9

Name of macro workbook: combine-Macro-Final
 
Upvote 0
What is the name of the destination sheet?
 
Upvote 0
Sheet 2 - I didn't give any particular name
 
Upvote 0
Try:
VBA Code:
Sub CopySheets()
    Application.ScreenUpdating = False
    Dim wsDest As Worksheet, wkbSource As Workbook, FolderName As String
    Set wsDest = ThisWorkbook.Sheets("Sheet2")
    With Application.FileDialog(msoFileDialogFolderPicker)
       .AllowMultiSelect = False
       .Show
       FolderName = .SelectedItems(1) & "\"
    End With
    ChDir FolderName
    strExtension = Dir("*.xls*")
    Do While strExtension <> ""
        Set wkbSource = Workbooks.Open(FolderName & strExtension)
        With wkbSource
            .Sheets(1).UsedRange.Offset(1).Copy wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1)
            .Close False
        End With
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Yeah it's working fine..thank you so much... Do know how much this meant to me,I have failed 6 times ,I dnt know anything about macros,just I tried seeing tutorials on YouTube but that doesn't work.. You saved me lot.????
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,399
Members
449,447
Latest member
M V Arun

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