+ Reply to Thread
Results 1 to 9 of 9

Need a Macro to group certain columns and save them as a separate file in specific folder

Hybrid View

  1. #1
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    584

    Smile Need a Macro to group certain columns and save them as a separate file in specific folder

    Dear Friends,

    I have more than 1000 rows and 100 columns of data.

    I need a MACRO to separate Cols. A, B along with unique values in Row #2 then that file should be saved in a separate folder as per the value in Col.B.

    I attached a sample file in which I furnished all details.

    I request your kind help.
    Attached Files Attached Files
    Last edited by acsishere; 07-29-2013 at 11:01 AM.
    Good friends are hard to find, harder to leave, and impossible to forget.

    acsishere.

  2. #2
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    584

    Re: Need a Macro to group certain columns and save them as a separate file in a specific f

    Request kind help... please...

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need a Macro to group certain columns and save them as a separate file in a specific f

    Maybe:

    Sub acsishere()
    Dim i As Long
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set ws = ActiveSheet
    ws.Copy Before:=Sheets(1)
    ActiveSheet.Name = "Helper"
        Range(Cells(1, 3), Cells(ActiveSheet.UsedRange.Rows.count, ActiveSheet.UsedRange.Columns.count)).Select
        Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:=Range("C1") _
            , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
            False, Orientation:=xlLeftToRight, DataOption1:=xlSortNormal, DataOption2 _
            :=xlSortNormal
    For i = 3 To ActiveSheet.Columns.count - 2 Step 2
            If i < 19 Then
            ws.Range("A1:B" & ActiveSheet.UsedRange.Rows.count + 1).Copy
            Sheets.Add.Name = Cells(2, i).Value
            Range("A1").PasteSpecial xlPasteAll
            End If
            Sheets("Helper").Activate
    Next i
    Sheets("Helper").Activate
    For i = 3 To ActiveSheet.Columns.count - 3 Step 2
            If i < 19 Then
            If Cells(2, i).Value = Cells(2, i).Offset(, 1).Value Then
            Sheets("Helper").Range(Cells(1, i), Cells(ActiveSheet.UsedRange.Rows.count + 1, i + 1)).Copy Sheets(Cells(2, i).Value).Range("C1")
            End If
            If Cells(2, i).Value <> Cells(2, i).Offset(, 1).Value Then
            Sheets("Helper").Range(Cells(1, i), Cells(ActiveSheet.UsedRange.Rows.count + 1, i)).Copy Sheets(Cells(2, i).Value).Range("C1")
            End If
            Sheets("Helper").Activate
            End If
    Next i
    ActiveSheet.Select
    ActiveWindow.SelectedSheets.Delete
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    End Sub
    Last edited by JOHN H. DAVIS; 07-29-2013 at 02:37 PM.

  4. #4
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    584

    Re: Need a Macro to group certain columns and save them as a separate file in specific fol

    Dear Sir,

    Thanks for your magical code. It solves the purpose. A little error I found, when executed.

    I request your magic hand to clear the problem.

    Please Sir...
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need a Macro to group certain columns and save them as a separate file in specific fol

    I received your PM. The reason the macro is not working now is that you revised your requirements. You added another Jun-13 for "AAA". That would cause the error you are receiving. The macro steps by 2 and creates sheets based on pairs or one. How many elements for each sheet can there be?

  6. #6
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    584

    Smile Need a Macro to group certain columns and save them as a separate file in specific fol

    Dear Sir,

    Thanks for your kindness & reply.

    Actually, the data is only the sample to show the requirements.

    The minimum & maximum number of elements will be: from 1 to 12. (i.e. number of each elements may vary from 1 to 12).

    Request your kind help.

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need a Macro to group certain columns and save them as a separate file in specific fol

    Try this:

    Sub acsishere()
    Dim i As Long
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set ws = ActiveSheet
    ws.Copy Before:=Sheets(1)
    ActiveSheet.Name = "Helper"
        Range(Cells(1, 3), Cells(ActiveSheet.UsedRange.Rows.count, ActiveSheet.UsedRange.Columns.count)).Select
        Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:=Range("C1") _
            , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
            False, Orientation:=xlLeftToRight, DataOption1:=xlSortNormal, DataOption2 _
            :=xlSortNormal
    On Error GoTo Z:
    For i = 3 To ActiveSheet.Columns.count + 1
            If Cells(2, i).Text <> Cells(2, i + 1).Text Then
            ws.Range("A1:B" & ActiveSheet.UsedRange.Rows.count + 1).Copy
            Sheets.Add.Name = Cells(2, i).Value
            Range("A1").PasteSpecial xlPasteAll
            End If
            Sheets("Helper").Activate
    Next i
    Z:
    Range("C2").Select
    Do Until ActiveCell.Value = ""
        Range(ActiveCell.Offset(-1), ActiveCell.Offset(5)).Copy Sheets(ActiveCell.Value).Cells(1, Sheets(ActiveCell.Value).UsedRange.Columns.count + 1)
        Sheets("Helper").Activate
        ActiveCell.Offset(, 1).Select
    Loop
    ActiveSheet.Select
    ActiveWindow.SelectedSheets.Delete
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    End Sub

  8. #8
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    584

    Re: Need a Macro to group certain columns and save them as a separate file in specific fol

    Sir, Excellent. It's working nicely. No words to express my Gratitude.

    Thanks. Thanks a lot. It solved my huge task.

    Regards.

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need a Macro to group certain columns and save them as a separate file in specific fol

    You're welcome. Glad to help out and thanks for the feedback and reps.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 07-11-2013, 02:08 AM
  2. [SOLVED] macro to save file to specific folder with file name from cell reference
    By mezza89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-06-2013, 11:32 AM
  3. [SOLVED] Macro to group columns based on specific criteria in entire workbook
    By kbkumar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-09-2012, 04:47 AM
  4. [SOLVED] request macro to save file to multiple, separate locations
    By Joseph Spain in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-26-2005, 10:46 AM
  5. How do I save each sheet as a separate .xls file by using macro?
    By Min in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-18-2005, 10:06 AM

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