+ Reply to Thread
Results 1 to 2 of 2

macro to export 2 worksheets to new workbook, do until end

  1. #1
    Registered User
    Join Date
    08-16-2010
    Location
    us
    MS-Off Ver
    Excel 2007
    Posts
    21

    Question macro to export 2 worksheets to new workbook, do until end

    I have a macro that starts at worksheet 4 and exports it to a new workbook and saves it in the location listed below.
    I would like to modify it so that it take worksheet 5 and 6 and exports both into a new workbook, then 7 & 8, 9 & 10, until it get to the last worksheet.

    any suggestions?


    Dim i As Long
    Dim NewWks As Worksheet


    For i = 4 To ActiveWorkbook.Worksheets.Count
    Sheets(i).Copy 'to new workbook
    Set NewWks = ActiveSheet
    With NewWks.Parent
    Application.DisplayAlerts = False
    .Saveas Filename:="F:\Macros\" & NewWks.Name & ".xls", FileFormat:=56
    Application.DisplayAlerts = True
    .Close SaveChanges:=False
    End With
    Next i
    MsgBox "Done!"

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: macro to export 2 worksheets to new workbook, do until end

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1