Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    May 2005
    Location
    Wilcox, Saskatchewan
    Posts
    171
    Thanks
    0
    Thanked 0 Times in 0 Posts

    reverse cell order lowest to high (excel)

    I am tring to reverse a selection of rows and columns. I have attached a .xls for an example. The height category is the controlling row. the numbers are listed, high to low and I want them low to high. I have work the macro below this to reverse the cells but it doesnt do what i need, Im limited in my program skill to make it do what I want. The rows width and change and the row above must move with the height value is kinda like a sort.

    I thank you ahead for taking for a look

    Function ReverseCell(Rcell As Range, Optional IsText As Boolean)
    Dim i As Integer
    Dim StrNewNum As String
    Dim strOld As String

    strOld = Trim(Rcell)

    For i = 1 To Len(strOld)
    StrNewNum = Mid(strOld, i, 1) & StrNewNum
    Next i

    If IsText = False Then
    ReverseCell = CLng(StrNewNum)
    Else
    ReverseCell = StrNewNum
    End If
    End Function

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: reverse cell order lowest to high (excel)

    Why not just sort Left to right?

    You can do it manually (data - sort - options)
    or

    with 1 line of code:

    <pre>Range("C15:K18").Sort _
    Key1:=Range("C16"), Order1:=xlAscending, _
    Header:=xlGuess, OrderCustom:=1, _
    MatchCase:=False, _
    Orientation:=xlLeftToRight</pre>


    Steve

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: reverse cell order lowest to high (excel)

    You can do this interactively (without code):
    - Select C15:K18.
    - Select Data | Sort...
    - Click Options...
    - Click Left to Right, then click OK.
    - Specify that you want to sort on Row 16.
    - Click OK.

    In code:

    Range(Range("C15"), Range("C15").End(xlToRight).End(xlDown)).Sort _
    Orientation:=xlLeftToRight, Key1:=Range("C16"), Order1:=xlAscending

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •