+ Reply to Thread
Results 1 to 3 of 3

Macro to reformat spreadsheet?

Hybrid View

  1. #1
    Registered User
    Join Date
    02-08-2010
    Location
    Wilmington, Delaware
    MS-Off Ver
    Excel 2003
    Posts
    1

    Thumbs down Macro to reformat spreadsheet?

    I am importing data into a spreadsheet. Each record has 6 to 11 fields. The data gets imported as one long list...so all date is in colum A. The first record in cells a1 to a11, then a space, then the second in a12 to a20, space...and so on. I want to transpose the records so the data goes across the colums (A through K). I know I can transpose it on record at a time using the Paste->transpose data command...but there are many records and this will take days. How can I create a macro to transpose the entire worksheet at once??

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to reformat spreadsheet?

    Try this on a copy of your data, it will only copy once per area...
    Option Explicit
    
    Sub ReformatData()
    'JBeaucaire  2/8/2010
    'Reorganize groups of data in column A into row format
    Dim i As Long, RNG As Range
    Application.ScreenUpdating = False
    
    Set RNG = Columns("A:A").SpecialCells(xlCellTypeConstants)
    
    For i = 1 To RNG.Areas.Count
        RNG.Areas(i).Copy
        Range("B" & i).PasteSpecial xlPasteAll, Transpose:=True
    Next i
    
    Columns(1).Delete xlShiftToLeft
    Application.ScreenUpdating = True
    End Sub

    It blew through 5500 rows of data, 650 "groups" in about 3 seconds.
    Last edited by JBeaucaire; 02-08-2010 at 07:49 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to reformat spreadsheet?

    Did this work for you?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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