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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,215,516
Messages
6,125,284
Members
449,218
Latest member
Excel Master

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