+ Reply to Thread
Results 1 to 6 of 6

Sorting data

Hybrid View

  1. #1
    Registered User
    Join Date
    10-29-2012
    Location
    hyderabad, India
    MS-Off Ver
    Excel 2007
    Posts
    53

    Sorting data

    hi,

    i have data in the below fashion:

    A B C
    a,b,c,d 1,2,3,4 q,w,e,r

    what i need to do is to convert the above into :

    A B C
    a 1 q
    b 2 w
    c 3 e
    d 4 r

    thanks in advance.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Sorting data

    sidd.iths,

    this is not a lot of information, can you share a workbook to illustrate what the data looks like? maybe a sheet that shows current data, and another with expected results?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    10-29-2012
    Location
    hyderabad, India
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Sorting data

    hi Arkadi,

    have attached a file, hope this helps.

    thanks
    Attached Files Attached Files

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Sorting data

    sidd,

    I have tried to make the macro easy to edit in case your example does not use the same columns/rows as original, let me know if you have problems:

    Sub sidd_iths()
    
    Dim ws1 As Worksheet 'the sheet with the source data
    Dim ws2 As Worksheet 'the new sheet with sorted data
    Dim grouped_data 'to break up the information with commas
    Dim cols As Long 'how many columns need sorting (A,B,C,etc)
    Dim fcol As Long 'the first column with ABC data
    Dim rw As Long 'the row with the "A","B","C"
    
    Set ws1 = Worksheets("Sheet1") 'change the sheet name to the one with the original data
    
    'below is the part you need to change to customize for your sheet layout
    rw = 3 'the top row with "A" "B" "C" info was 3 in example, change as needed
    cols = 3 'change to how many columns have data (3 in example, ABC)
    fcol = 2 'this was the column with "A" in example, change as needed
    'end of what you need to edit
    
    Set ws2 = Sheets.Add
    ws2.Range(Cells(1, 1), Cells(1, cols)).Value = ws1.Range(ws1.Cells(rw, fcol), ws1.Cells(rw, fcol + cols)).Value
    For i = 0 To cols
        grouped_data = Split(ws1.Cells(rw + 1, fcol + i), ",")
        For j = 2 To UBound(grouped_data) + 2
            ws2.Cells(j, 1 + i).Value = grouped_data(j - 2)
        Next j
    Next i
    
    End Sub

  5. #5
    Registered User
    Join Date
    10-29-2012
    Location
    hyderabad, India
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Sorting data

    hi Arkadi,

    Thanks that works for the first row, could you edit the code to get results for multiple rows of data in the same format.

    Thanks

  6. #6
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Sorting data

    Option Explicit
    
    
    
    Sub makeRows()
    
    Dim source As Worksheet
    Dim destination As Worksheet
    Dim cols As Long, i As Long, j As Long, k As Long
    Dim stringArray() As String
    
    
    'Adjust for you'
    Set source = ThisWorkbook.Sheets(1)
    Set destination = ThisWorkbook.Sheets(2)
    cols = 3
    For i = 2 To source.Cells(Rows.Count, 1).End(xlUp).Row
        For j = 1 To cols
            ReDim stringArray(0 To UBound(Split(source.Cells(i, j), ",")))
            stringArray = Split(source.Cells(i, j), ",")
            For k = 0 To UBound(stringArray)
                destination.Cells(Rows.Count, j).End(xlUp).Offset(1, 0) = stringArray(k)
            Next
        Next j
    Next i
    
    End Sub

    See attached:
    Attached Files Attached Files
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

+ 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. Replies: 0
    Last Post: 02-24-2014, 11:27 AM
  2. [SOLVED] Data Analysis: Comparing 3 columns, sorting, removing unique values, display data
    By kmills2626 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-14-2013, 07:27 AM
  3. Sorting 2 data ranges by comparing one column in each and sorting to match
    By MDKsmiffy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-17-2013, 03:30 PM
  4. Replies: 3
    Last Post: 12-20-2012, 06:16 AM
  5. Sorting, finding dulicates, moving one data element up, deleting original data
    By rickwtx in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 01-13-2011, 07:32 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