+ Reply to Thread
Results 1 to 2 of 2

Macro to Automate Transpose column to rows Excel 2010

Hybrid View

Rayb1969 Macro to Automate Transpose... 06-08-2012, 04:13 PM
AlphaFrog Re: Macro to Automate... 06-08-2012, 06:51 PM
  1. #1
    Registered User
    Join Date
    06-08-2012
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    1

    Macro to Automate Transpose column to rows Excel 2010

    I have worked with Excel a lot but have never used Macros and I do not know much about Programming

    I get .txt files with 2 columns of info
    Column A info keeps track of column B data
    Column A data '00' = start of a new record (shows in A1, A36, A71, etc)
    Column B is data that needs to TRANSPOSE
    There is always some rows that are blank, and need to be blank after TRANSPOSE


    Every 35 Rows of Column B equals one record
    this needs to TRANSPOSE to 1 row with 35 columns, starting at C2 or on a new sheet at A2

    the total data in Column B may very each time from 175 rows to 70,000 rows.
    After TRANSPOSE, the result would be 5 rows to 2000 rows
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Macro to Automate Transpose column to rows Excel 2010

    Sub Transpose_Records()
    
        Dim vData As Variant
        Dim i As Long, Lastrow As Long
        
        'Read all data from sheet 1 column B
        With Sheets(1) 'Source worksheet
            Lastrow = .Range("B" & Rows.Count).End(xlUp).Row
            ReDim vData(1 To Int((Lastrow + 34) / 35))
            For i = 1 To Lastrow Step 35
                vData(Int(i / 35) + 1) = .Range("B1").Offset(i - 1).Resize(35).Value
            Next i
        End With
        
        'Transpose records
        Application.ScreenUpdating = False
        With Sheets(2)  ' Destination worksheet
            For i = 1 To UBound(vData)
                .Range("A" & i + 1).Resize(, 35).Value = Application.Transpose(vData(i))
            Next i
        End With
        Application.ScreenUpdating = True
    
    End Sub

+ 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