VBA loop to export specific sheets from workbook

p4nny

Board Regular
Joined
Jan 13, 2015
Messages
246
Hi

I would like a macro that would select specific sheets based off the tab name using a list on a separate tab, move them to a new workbook and save in a location that i would specify (Locally).

Basically, in a one excel sheet I have list of salesman's names (tab is called ‘TM list’ and a corresponding tab in the same workbook matching those names.

What I would like is the macro to select a name of Salesman from the list, move it to new workbook along with a tab called raw data (and hide in the newly created workbook and also the in the active select cell B13 before saving.
I suppose the rule would be along lines of ... loop until column A in salesman list is blank.
Ideally it would save the name of the tab plus todays date would be great.

Appreciate your help, Hope this is clear.

Anthony
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Perhaps something like this.
Code:
Dim wbNew As Workbook
Dim rngTM As Range
Dim strPath As String

    Application.ScreenUpdating = False

    strPath = "C:\PathToFolder\You\Want\ToSaveTo\"
    Set rngTM = Sheets("TM List").Range("A2")

    Do
        Sheets(Array("Raw Data", rngTM.Value)).Copy
        Set wbNew = ActiveWorkbook
        With wbNew
            .Sheets("Raw Data").Visible = False
            Application.Goto .Sheets(1).Range("B13"), True
            SaveAs strPath & rngTM.Value & Format(Date, "ddmmmyyyy") & ".xlsx, xlOpenXMLWorkbook
            .Close
         End With
         Set rngTM = rngTM.Offset(1)
    Loop Until rngTM.Value   

    Application.ScreenUpdating = True
 
Upvote 0
this works great.. Just one question, what is "sheets(1)"? Many thanks for your help
 
Upvote 0

Forum statistics

Threads
1,216,745
Messages
6,132,473
Members
449,729
Latest member
davelevnt

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