+ Reply to Thread
Results 1 to 7 of 7

Transpose Batch Excel Data

Hybrid View

  1. #1
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Transpose Batch Excel Data

    Just in case you want a different option, here is a code process:

    Option Explicit
    
    
    Sub TransformROWSTOCOL()
    
    Dim rsht1 As Long, rsht2 As Long, i As Long, Col As Long
    Dim wsTest As Worksheet, mr As Worksheet, ms As Worksheet
    Dim c As Range
    
    'check if sheet "ouput" already exist
    
    Const strSheetName As String = "Transform"
    
    Set wsTest = Nothing
    On Error Resume Next
    Set wsTest = ActiveWorkbook.Worksheets(strSheetName)
    On Error GoTo 0
     
    If wsTest Is Nothing Then
        Worksheets.Add.Name = strSheetName
    End If
    
    'set the data
                     
    Set mr = Sheets("Original Data") 'this is the name of the source sheet
    Set ms = Sheets("Transform")     'this is the name of the destiny sheet
    Col = 5
    'End set the data
        With ms
         .UsedRange.ClearContents
         .Range("A1:D1").Value = Array("Origin City", "Origin State", "Destination City", "Destination State")
        End With
        rsht2 = ms.Range("A" & Rows.Count).End(xlUp).Row
        With mr
              rsht1 = .Range("A" & .Rows.Count).End(xlUp).Row
              For i = 2 To rsht1
                    Do While .Cells(1, Col).Value <> ""
                    rsht2 = rsht2 + 1
                    ms.Range("A" & rsht2).Value = .Range("A" & i).Value
                    ms.Range("B" & rsht2).Value = .Range("B" & i).Value
                    ms.Range("C" & rsht2).Value = .Range("C" & i).Value
                    ms.Range("D" & rsht2).Value = .Range("D" & i).Value
                    ms.Range("E" & rsht2).Value = .Cells(1, Col).Value
                    ms.Range("F" & rsht2).Value = .Cells(2, Col).Value
                    ms.Range("G" & rsht2).Value = .Cells(i, Col).Value
                    
                    Col = Col + 1
                Loop
                Col = 2
            Next
        End With
        
      With ms
        .Range("F2:F" & .Rows.Count).SpecialCells(Type:=xlCellTypeBlanks).EntireRow.Delete
        .Columns("A:D").EntireColumn.AutoFit
        End With
        
    End Sub
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    01-05-2016
    Location
    Texas, USA
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Transpose Batch Excel Data

    Quote Originally Posted by maniacb View Post
    Just in case you want a different option, here is a code process:

    Option Explicit
    
    
    Sub TransformROWSTOCOL()
    
    Dim rsht1 As Long, rsht2 As Long, i As Long, Col As Long
    Dim wsTest As Worksheet, mr As Worksheet, ms As Worksheet
    Dim c As Range
    
    'check if sheet "ouput" already exist
    
    Const strSheetName As String = "Transform"
    
    Set wsTest = Nothing
    On Error Resume Next
    Set wsTest = ActiveWorkbook.Worksheets(strSheetName)
    On Error GoTo 0
     
    If wsTest Is Nothing Then
        Worksheets.Add.Name = strSheetName
    End If
    
    'set the data
                     
    Set mr = Sheets("Original Data") 'this is the name of the source sheet
    Set ms = Sheets("Transform")     'this is the name of the destiny sheet
    Col = 5
    'End set the data
        With ms
         .UsedRange.ClearContents
         .Range("A1:D1").Value = Array("Origin City", "Origin State", "Destination City", "Destination State")
        End With
        rsht2 = ms.Range("A" & Rows.Count).End(xlUp).Row
        With mr
              rsht1 = .Range("A" & .Rows.Count).End(xlUp).Row
              For i = 2 To rsht1
                    Do While .Cells(1, Col).Value <> ""
                    rsht2 = rsht2 + 1
                    ms.Range("A" & rsht2).Value = .Range("A" & i).Value
                    ms.Range("B" & rsht2).Value = .Range("B" & i).Value
                    ms.Range("C" & rsht2).Value = .Range("C" & i).Value
                    ms.Range("D" & rsht2).Value = .Range("D" & i).Value
                    ms.Range("E" & rsht2).Value = .Cells(1, Col).Value
                    ms.Range("F" & rsht2).Value = .Cells(2, Col).Value
                    ms.Range("G" & rsht2).Value = .Cells(i, Col).Value
                    
                    Col = Col + 1
                Loop
                Col = 2
            Next
        End With
        
      With ms
        .Range("F2:F" & .Rows.Count).SpecialCells(Type:=xlCellTypeBlanks).EntireRow.Delete
        .Columns("A:D").EntireColumn.AutoFit
        End With
        
    End Sub
    Thank you. This does provide me with another option as I have to do a bunch of these every month. I appreciate you taking the time to respond!

+ 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. Batch Transpose
    By probuddha in forum Excel General
    Replies: 3
    Last Post: 01-12-2017, 08:05 AM
  2. [SOLVED] Aggregate Batch Data from many word docs into an Excel (i.e.Check Boxes, Text Form Fields)
    By Chrisdudley7 in forum Word Formatting & General
    Replies: 7
    Last Post: 05-13-2014, 01:28 PM
  3. [SOLVED] Formula to round down on a batch and exclude anything under a full batch
    By toomuchbrew in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-15-2012, 11:04 AM
  4. Replies: 0
    Last Post: 06-19-2012, 11:36 AM
  5. [SOLVED] Batch extract PDF data to Excel using regular expressions
    By dwilkie@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-25-2006, 05:15 AM
  6. How to batch create / generate and print invoices from Excel data?
    By helenerz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2005, 10:05 PM
  7. Excel charts data auto range / batch update ?
    By agb in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-22-2005, 10:44 AM

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