+ Reply to Thread
Results 1 to 2 of 2

Transpose required.

Hybrid View

  1. #1
    Registered User
    Join Date
    12-30-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    31

    Transpose required.

    Hey Guys,

    I have this below input table which i wanted to transpose as shown in Output. Request someone to help me.


    Input
    ----------
    |ORG |CRG|
    ----------
    |A90 | |
    |A90 |A90|
    |A90 |A92|
    |A90 |A95|
    |A90 |A98|
    |A90 |A99|
    |A92 |A90|
    |A92 |A92|
    |A92 |A95|
    |A92 |A98|
    |A92 |A99|
    |A92 |B77|
    |A92 |B78|
    |A92 |B82|
    |A92 |B87|
    |A95 |A90|
    |A95 |G9 |
    |A95 |H8 |
    |A95 |H7 |
    |A95 |H6 |
    |A95 |H5 |
    |A95 |H4 |
    |A95 |H3 |
    |A95 |H2 |
    ------------



    Output required
    -------------------------------------------------------------------------------------
    ORG | CRJ |
    -------------------------------------------------------------------------------------
    A90 | IN("", "A90", "A92", "A95", "A98", "A99") |
    A92 | IN("A90", "A92", "A95", "A98", "A99", "B77", "B78", "B82", "B87") |
    A95 | IN("A90", "G9", "H8", "H7", "H6", "H5", "H4", "H3", "H2") |
    ---------------------------------------------------------------------------------------


    Also attached sample excel file.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Transpose required.

    VBA option
    - run in attached workbook with {CTRL} k
    - Results are based on values in sheet "Data"

    Sub ProcessAndTransform()
    'variables
        Dim coll As New Collection, i As Long, cel As Range, rStr As String, res As String
        Dim rng As Range: Set rng = Data.Range("A2", Data.Range("A" & Rows.Count).End(3))
    'column headers
        Results.Range("A1:B1").Value = Data.Range("A1:B1").Value
    'create unique list in collection
        For Each cel In rng
            On Error Resume Next
                coll.Add cel.Value, cel.Value
            On Error GoTo 0
        Next cel
    'build string and write to worksheet
        For i = 1 To coll.Count
            For Each cel In rng
                res = cel.Offset(, 1).Value
                If res = vbNullString Then res = Chr(34) & Chr(34)
                If coll(i) = cel.Value Then
                   rStr = rStr & "," & res
                End If
            Next cel
                Results.Cells(i + 1, 1) = coll(i)
                Results.Cells(i + 1, 2) = Right(rStr, Len(rStr) - 1)
                rStr = ""
        Next i
    End Sub
    Explanatory notes
    - use of collection to create a unique list of values because collections do not allow duplicate keys
    - sheets are referred via their codenames not their tab names (here they happen to be identical)
    Attached Files Attached Files
    Last edited by kev_; 03-09-2018 at 05:09 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

+ 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. transpose column to a range calculate and transpose to new table loop
    By moshro1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-02-2015, 10:52 AM
  2. [SOLVED] IF & TRANSPOSE Formula required
    By shrubfact in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 04-05-2014, 05:32 PM
  3. Macro required to transpose data
    By oneeasygeezer in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 07-01-2013, 10:51 AM
  4. [SOLVED] Excel 2007 : Transpose Data:Advanced Help required
    By ahmadomer63 in forum Excel General
    Replies: 2
    Last Post: 06-01-2012, 06:15 AM
  5. [SOLVED] Transpose: How can I copy a list and transpose it but leaving 3 cells in between each item
    By cocolete in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-11-2012, 10:01 AM
  6. Slight tweaking Required to a Search & Transpose Macro
    By frank933 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2011, 05:05 AM
  7. Replies: 2
    Last Post: 02-19-2007, 04:53 PM

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