+ Reply to Thread
Results 1 to 5 of 5

Macro to sort multiple ranges on a worksheet

  1. #1
    Registered User
    Join Date
    10-30-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    12

    Macro to sort multiple ranges on a worksheet

    Hi Guys -

    Could someone please help me out to sort multiple ranges on a worksheet.

    I have attached an excel file where I need to sort the set of data("A:H") based on column "G".

    Have shown a difference of Raw data and Required output on the attached file.

    All I require is to sort the set of data("A:H") using column "G" ("Status").

    Any help would be greatly appreciated.

    Many thanks in advance.

    Regards,
    Nikki
    Attached Files Attached Files

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

    Re: Macro to sort multiple ranges on a worksheet

    Put this formula in cell I2 and Drag-Copy it down column I for each entry.
    =IF(F2="",F1,F2)

    Then select column A:I. Sort on column I and by column Status (G)

    You could delete column I after the sort.

  3. #3
    Registered User
    Join Date
    10-30-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Macro to sort multiple ranges on a worksheet

    Hi,

    Many thanks for your response.

    I tried with the formula which you have provided and I could able to sort only column "G" not the entire data. And also, I tried sorting first on column I and then on column G separately, it sorts but merges everything, this is not what I required.

    Basically, the set of data which is segregated should remain As-Is after sorting also with the blanks, I do not want to merge everything, I just want to keep the multiple ranges separately. The idea is to know the count of each status for each type so. You can see the required output sheet on the attached. I want whole data(columns A to H) should be sorted using column "G".

    I have a macro, but its not working. Please have a look on this and try if you can fix this according to the requirement.

    ------------------------------------------------------------------------------------------------------------------------

    Option Explicit
    Sub test()
    Dim myAreas As Areas, myArea As Range, x As Long
    'On Error Resume Next
    Set myAreas = Range("g2", Range("g" & Rows.Count).End(xlUp)).SpecialCells(2).Areas
    'On Error GoTo 0
    If myAreas Is Nothing Then Exit Sub
    x = Range("a1").CurrentRegion.Columns.Count
    For Each myArea In myAreas
    With myArea
    With .Offset(1).Resize(.Rows.Count - 1, x)
    .sort Key1:=.Cells(1), Order1:=1, Header:=xlYes
    End With
    End With
    Next
    Set myAreas = Nothing
    End Sub

    ----------------------------------------------------------------------------------------------------------------------------

    Regards,
    Nikki

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

    Re: Macro to sort multiple ranges on a worksheet

    Try this...
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-30-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Macro to sort multiple ranges on a worksheet

    Hi,

    Many thanks for your great help.

    The macro which you have provided is working perfectly, this is what all I required. Its awesome!!!!

    Thanks again

    Regards,
    Nikki

+ 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