Excel masterfile vba

moshc

New Member
Joined
Oct 24, 2019
Messages
6
Good day!

Anyone can help me please?

I've been looking for an EXCEL VBA code in which i will have the option to select a folder path first which all the workbooks i need to combined is saved and have all the first sheets in all workbook in that specific folder is then combined to a new workbook.

Would really much appreciate any immediate response.

Thank you!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Open a blank workbook, place this macro in a standard module and save the workbook as a macro-enabled file. Run the macro.
Code:
Sub CopySheets()
    Application.ScreenUpdating = False
    Dim MyFolder As String, MyFile As String, srcWB As Workbook, desWB As Workbook
    Set desWB = ThisWorkbook
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Please select a folder"
        .Show
        .AllowMultiSelect = False
        If .SelectedItems.Count = 0 Then
            MsgBox "You did not select a folder."
            Exit Sub
        End If
        MyFolder = .SelectedItems(1) & "\"
    End With
    MyFile = Dir(MyFolder)
    Do While MyFile <> ""
        Set srcWB = Workbooks.Open(Filename:=MyFolder & "\" & MyFile)
        With srcWB
            .Sheets(1).Copy desWB.Sheets(desWB.Sheets.Count)
            .Close False
        End With
        MyFile = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Works perfectly thank you so much! Although apologies if i have follow up help needed, do you know any code where data copied to the new workbook are paste as values only? Like the files i needed to combined has formula in it and drop down menus.
 
Upvote 0
Try:
Code:
Sub CopySheets()
    Application.ScreenUpdating = False
    Dim MyFolder As String, MyFile As String, srcWB As Workbook, desWB As Workbook
    Set desWB = ThisWorkbook
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Please select a folder"
        .Show
        .AllowMultiSelect = False
        If .SelectedItems.Count = 0 Then
            MsgBox "You did not select a folder."
            Exit Sub
        End If
        MyFolder = .SelectedItems(1) & "\"
    End With
    MyFile = Dir(MyFolder)
    Do While MyFile <> ""
        Set srcWB = Workbooks.Open(Filename:=MyFolder & "\" & MyFile)
        With srcWB
            .Sheets(1).Copy desWB.Sheets(desWB.Sheets.Count)
            With ActiveSheet.UsedRange
                .Cells.Validation.Delete
                .Cells.Value = .Cells.Value
            End With
            .Close False
        End With
        MyFile = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Can you help me as well with vba code? I'm trying to figure out a way how to automatically click don't update on the excel file that i've been working on.
 
Upvote 0
@tech3
Welcome to the Forum. According to Forum rules, you should not post your question in another member's thread. Please start your own new thread explaining in detail what you want to do.
 
Upvote 0
Ooh my apologies mumps, I'm only new and was kinda of in a rush for answer. really sorry about it. I however have posted a thread as well can you help me on that?
 
Upvote 0
It's me again! Need additional help on the vba code provided please. the sheets i'm trying to copy are protected and i'm having error prompt when executing the command. please anyone?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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