+ Reply to Thread
Results 1 to 3 of 3

Using Macro to separate a spreadsheet and create tabs for each month

Hybrid View

  1. #1
    Registered User
    Join Date
    10-13-2010
    Location
    Miami, US
    MS-Off Ver
    Excel 2007
    Posts
    83

    Using Macro to separate a spreadsheet and create tabs for each month

    Hi,

    Can some please help, separating and creating tabs within a single spreadsheet based on month?

    I actually download a full file which has months from Jan to June or sometimes Jan. to Dec. I have to separate and create different tabs for each month. I copy paste them manually (file attached). Is there a way to do it using Macro?

    Thanxxx a lot in advance,
    Ajang
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Mexico
    Posts
    200

    Re: Using Macro to separate a spreadsheet and create tabs for each month

    One way here:
    http://www.contextures.com/AdvFilterRepFiltered.zip

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Using Macro to separate a spreadsheet and create tabs for each month

    Hi ajang,

    Try this:

    Option Explicit
    Sub Macro1()
    
        'Written by Trebor76
        'Visit my website www.excelguru.net.au
        
        Dim rngCell As Range
        Dim wstSourceTab As Worksheet
        Dim lngPasteRow As Long
        Dim strTest As String
        
        Set wstSourceTab = Sheets("download-14") 'tab containing raw data. Change to suit.
        
        Application.ScreenUpdating = False
        
        For Each rngCell In wstSourceTab.Range("J2:J" & wstSourceTab.Range("J" & Rows.Count).End(xlUp).Row)
            'Create any tabs that don't already exist
            On Error Resume Next
                strTest = Sheets(CStr(Format(rngCell, "mmmm"))).Range("A1")
                If Err.Number = 9 Then 'An error number of 9 indicates that no such tab exists
                    Worksheets.Add after:=Worksheets(Worksheets.Count)
                    Worksheets(Worksheets.Count).Name = Format(rngCell, "mmmm")
                    'Put headers in
                    Sheets(CStr(Format(rngCell, "mmmm"))).Range("A1:O1").Value = wstSourceTab.Range("A1:O1").Value
                End If
            On Error GoTo 0
            'Copy the data from the 'wstSourceTab' tab to the relevant month tab
            lngPasteRow = Sheets(CStr(Format(rngCell, "mmmm"))).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
            Sheets(CStr(Format(rngCell, "mmmm"))).Range("A" & lngPasteRow & ":O" & lngPasteRow).Value = wstSourceTab.Range("A" & rngCell.Row & ":O" & rngCell.Row).Value
        Next rngCell
        
        Application.ScreenUpdating = True
        
        MsgBox "The data has now been copied from the """ & wstSourceTab.Name & """ tab across each applicable tab.", vbInformation, "Data Distribution Editor"
        
        Set wstSourceTab = Nothing
        
    End Sub
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

+ 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