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.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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).Copy after:=wkbDest.Sheets(wkbDest.Sheets.Count)
            .Close False
        End With
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
?...omg it worked...ur my life saviour.... thank you so much...??
 
Upvote 0
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).Copy after:=wkbDest.Sheets(wkbDest.Sheets.Count)
            .Close False
        End With
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
Hi mumps,

Also I need to create an macro, 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 in macro workbook sheet1 and also I want the header of all workbooks should be removed

Kindly help,
 
Upvote 0
Also,I need additional help can I able to add comman button
Add a command button on your sheet and assign the macro to it. If you need help on how to do this, please let me know.

I want the header of all workbooks should be removed
What do you mean by "Header"? Please explain in detail.
 
Upvote 0
I dnt need frist row of all workbooks need to be removed ,to be more clear the heading I dnt want. I have attached the image , kindly check it
 

Attachments

  • Screenshot_2021-05-20-22-28-54-47.png
    Screenshot_2021-05-20-22-28-54-47.png
    135.3 KB · Views: 4
Upvote 0
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).Rows(1).Delete
            .Sheets(1).Copy after:=wkbDest.Sheets(wkbDest.Sheets.Count)
            .Close False
        End With
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hey mumps,

It working fine but I need all the workbooks to be in one sheet that is sheet-2 of master workbook

Kindly help..
 
Upvote 0
I suggested a solution in your other post.
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,314
Members
449,153
Latest member
JazzSingerNL

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