+ Reply to Thread
Results 1 to 7 of 7

Export data from xlsx based on code name and save it to new xlsx with changed column name

Hybrid View

  1. #1
    Registered User
    Join Date
    01-11-2012
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    6

    Export data from xlsx based on code name and save it to new xlsx with changed column name

    Dear All,

    I would like to export data from excel file to separate files based on the code name (codes are in one of the column). There are around 60 codes.
    I would like that extracted data is saved to separate files with code names.
    Also, I would like to modify columns in the new file from SUFFIXn to <code + SUFFIXn>, eg. ASUFFIX1

    Exemplary input and outpu data is attached.

    Help would be appreciated,

    Regards,
    D.

    input.pngoutout.png
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    11-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    159

    Re: Export data from xlsx based on code name and save it to new xlsx with changed column n

    Quote Originally Posted by goldcoast View Post
    Dear All,
    Also, I would like to modify columns in the new file from SUFFIXn to <code + SUFFIXn>, eg. ASUFFIX1

    Attachment 176843Attachment 176844
    This is not so clear for me .

    you can try this code in sample test file
    Sub test()
     With ThisWorkbook
        Do Until .Sheets(1).Columns(4).SpecialCells(2).Count = 1
            c01 = .Sheets(1).Cells(2, 4).Value
            Workbooks.Add
    
        With .Sheets(1).Cells(1).CurrentRegion
             .AutoFilter 4, c01
             .Copy ActiveWorkbook.Sheets(1).Cells(1)
             .Offset(1).EntireRow.Delete
             .AutoFilter
        End With
        
       ActiveWorkbook.SaveAs .Path & "\" & c01, .FileFormat
       ActiveWorkbook.Close False
    Loop
    End With
    End Sub

  3. #3
    Registered User
    Join Date
    01-11-2012
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Export data from xlsx based on code name and save it to new xlsx with changed column n

    Thank you for your help.
    Macro works for the filtering part, however it does not change the heading name for column 5 from SUFFIX1 to ASUFFIX1, for column 6 from SUFFIX2 to ASUFFIX2 , where A is the code used for filtering.
    In case of code B we would have for column 5 from SUFFIX1 to BSUFFIX1, for column 6 from SUFFIX2 to BSUFFIX2 etc...

  4. #4
    Forum Contributor
    Join Date
    11-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    159

    Re: Export data from xlsx based on code name and save it to new xlsx with changed column n

    hi try dis code
    Sub test()
     With ThisWorkbook
        Do Until .Sheets(1).Columns(4).SpecialCells(2).Count = 1
            c01 = .Sheets(1).Cells(2, 4).Value
            Workbooks.Add
    
        With .Sheets(1).Cells(1).CurrentRegion
             .AutoFilter 4, c01
             .Copy ActiveWorkbook.Sheets(1).Cells(1)
                ActiveWorkbook.Activate
                For Each ccell In Sheets(1).Range("E1:n1")
                    ccell.Value = Range("D2").Value & ccell.Value
                Next ccell
                     Sheets(1).Range("E1:N1").Columns.AutoFit
                        
             .Offset(1).EntireRow.Delete
             .AutoFilter
        End With
        
       ActiveWorkbook.SaveAs .Path & "\" & c01, .FileFormat
       ActiveWorkbook.Close False
    Loop
    End With
    End Sub

  5. #5
    Registered User
    Join Date
    01-11-2012
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Export data from xlsx based on code name and save it to new xlsx with changed column n

    It works just excelent, thank you for your profesional help.
    Regards,
    D.

  6. #6
    Forum Contributor
    Join Date
    11-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    159

    Re: Export data from xlsx based on code name and save it to new xlsx with changed column n

    Thanks for feedback ! just mark as solved.
    Last edited by Cutter; 08-28-2012 at 10:19 AM. Reason: Removed whole post quote

  7. #7
    Registered User
    Join Date
    01-11-2012
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Export data from xlsx based on code name and save it to new xlsx with changed column n

    Unfortunatelly I have a problem running this macro on larger data with 260 000 rows and 30 columns (80MB file). Excel is freezing with informaion on the bar "not responding". I am running Excel 2010 on 64bit W7 8GB RAM.

    It works on small portion of the same data.
    Any suggestions???

+ 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