+ Reply to Thread
Results 1 to 4 of 4

Looking for an Automated & Smart Transpose solution

Hybrid View

Gumsolmao Looking for an Automated &... 05-07-2013, 11:02 PM
im.zeeshan Re: Looking for an Automated... 05-08-2013, 01:40 AM
arlu1201 Re: Looking for an Automated... 05-08-2013, 02:13 AM
Gumsolmao Re: Looking for an Automated... 05-09-2013, 01:38 AM
  1. #1
    Registered User
    Join Date
    11-30-2012
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    2

    Question Looking for an Automated & Smart Transpose solution

    So currently, per the title, I'm looking to make a smart and relatively automatic transpose system.

    So far the only way ive figured out how to do this is with macros, paste special, and a lot of manual work (working on 2,000~ row sheet).

    The following example is an example.
    All the events belong to A1 but are distributed downwards in a new row. The goal is to have them all in a single row (either in a single cell or adjacent).

    A 1 Event 1
    Event 2
    Event 3
    B 2 Group 1

    All the events belong to A1 but are distributed downwards in a new row. The goal is to have them all in a single row (either in a single cell or adjacent).
    The example of how I need them is demonstrate below.

    A 1 Event 1 Event 2 Event 3
    B 2 Group 1

    I have searched far and wide and haven't found anything which solves this bizarre request.

  2. #2
    Registered User
    Join Date
    05-03-2013
    Location
    Navi Mumbai, India
    MS-Off Ver
    Excel 2013
    Posts
    7

    Thumbs up Re: Looking for an Automated & Smart Transpose solution

    I'm assuming your data starts from Cell A1.

    Just add a row with hyphens to mark the end of the data sheet like;

    A 1 Event 1
    Event 2
    Event 3
    B 2 Group 1
    Group 2
    - - -


    Then run the following macro: (Your results will be displayed in Sheet 2)

    Sub SmartTranspose()
        j = 1
        For nRow = 1 To Sheets(1).UsedRange.Count
            If nRow = 1 Then
                sCategory = Cells(nRow, 1).Value
                sSubCategory = Cells(nRow, 2).Value
                sItem = Cells(nRow, 3).Value
            Else
                If Cells(nRow, 2).Value = "" Then
                    sItem = sItem & ";" & Cells(nRow, 3).Value
                Else
                    aItem = Split(sItem, ";")
                    Sheets(2).Cells(j, 1) = sCategory
                    Sheets(2).Cells(j, 2) = sSubCategory
                    c = 3
                    For x = 0 To UBound(aItem)
                        Sheets(2).Cells(j, c) = aItem(x)
                        c = c + 1
                    Next
                    sCategory = Cells(nRow, 1).Value
                    sSubCategory = Cells(nRow, 2).Value
                    sItem = Cells(nRow, 3).Value
                    j = j + 1
                End If
            End If
        Next
    
    End Sub
    Attached Files Attached Files
    Last edited by im.zeeshan; 05-08-2013 at 02:40 AM.
    www.LaunchPixels.com
    www.imZeeshan.com

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Looking for an Automated & Smart Transpose solution

    Try this code
    Sub transpose()
    Dim i As Long, lrow As Long, lcol As Long, lcol1 As Long
    
    Application.ScreenUpdating = False
    
    With Worksheets("Sheet1")
        lrow = .Range("C" & .Rows.Count).End(xlUp).Row
        For i = lrow To 2 Step -1
            If .Range("A" & i).Value = "" Then
                lcol = .Range("IV" & i - 1).End(xlToLeft).Column
                lcol1 = .Range("IV" & i).End(xlToLeft).Column
                .Range(.Cells(i, 2), .Cells(i, lcol1)).Copy .Cells(i - 1, lcol + 1)
                Application.CutCopyMode = False
                .Rows(i).Delete
            End If
        Next i
    End With
    
    MsgBox "Done"
    
    Application.ScreenUpdating = True
    
    End Sub
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    11-30-2012
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    2

    Re: Looking for an Automated & Smart Transpose solution

    I swear to god this place is full of witchcraft, thank you both so much.

+ 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