Save as Multiple sheets as in separate workbook

haribole

New Member
Joined
Apr 10, 2018
Messages
19
I have workbook containing above 40 worksheets. I want to save only 30 worksheets as excel in separate workbook. Please any body can help !!!

Code:
Dim wb As WorkbookDim ws As Workbook
Dim DateFrom As String, DateTo As String, UserName As String
Dim MySheetName() As String
Dim i As Integer
DateFrom = Worksheets(1).Cells(1, 1)
DateTo = Worksheets(1).Cells(2, 1)
UserName = InputBox("Enter Password")
If UserName = "****" Then

'Here I need the code


ReDim MySheetName(Sheets(DateFrom).Index To Sheets(DateTo).Index) As String
    For i = Sheets(DateFrom).Index To Sheets(DateTo).Index Step 1
    MySheetName(i) = Worksheets(i).Name
    Next i
       For i = Sheets(DateFrom).Index To Sheets(DateTo).Index Step 1
       Application.DisplayAlerts = False
       Sheets(MySheetName(i)).Delete
       Application.DisplayAlerts = True
       Next i
Else
Msgbox "Incorrect Password"
End If
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You haven't provided much info - how do you determine which sheets to save? Where will they be saved? How will their filename be derived?

The below (untested!) code shows you how to loop through every sheet in a file and save them to a new workbook
Code:
Sub Macro1()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
    ws.Copy
    With ActiveWorkbook
        .SaveAs "Filename"
        .Close
    End With
Next ws
End Sub
 
Upvote 0
How about
Code:
If UserName = "****" Then
ReDim MySheetName(Sheets(DateFrom).Index To Sheets(DateTo).Index) As String
    For i = Sheets(DateFrom).Index To Sheets(DateTo).Index Step 1
      MySheetName(i) = Worksheets(i).Name
    Next i
    Application.DisplayAlerts = False
    Sheets(MySheetName).Move
    Application.DisplayAlerts = True
Else
 
Upvote 0
Thanks !!!
1) DateFrom (from the sheet) to DateTo ( to the sheet)
2) MyFolder = "D:\NewCPCReport"
3) File name will derive from InputBox ("Enter File Name")
 
Upvote 0
Thanks !!! for your comments:
1) DateFrom (from sheet) to DateTo (to sheet)
2) MyFolder = "D:\NewCPCReport"
3) File name will be derived from InputBox ("Enter File Name") (as excel normal)
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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