Sorting Data Horizontally

Demni009

New Member
Joined
Mar 5, 2014
Messages
22
I need some help. I am teaching myself how to code in VBA and still have a lot to learn. I have a big block of data that I am trying to sort. I have been able to sort data vertically in the past by vba code. However, this time I want to sort data horizontally. I know my error is in the section labeled " 'organizes columns based of values in row 9 ". I can't figure out how to correct it. Can some one make it work and explain why mine is incorrect?

Cheers,
Demni009



Code:
Sub Calc()


Dim c As Integer


'Deletes values and replaces them with a blank cell
ActiveSheet.Rows(9).Delete
Range("A9").EntireRow.Insert


'Where to start summing
c = 4


'Sums values
    Do
        summed = Application.WorksheetFunction.Sum(Columns(c))
        Cells(9, c).Value = summed
        c = c + 1
    Loop Until Cells(15, c).Value = ""
    
'organizes columns based of values in row 9
org = Cells(Rows.Count, c).End(xlUp).Row


    With Sheets("RGA Data").Cells(Rows.Count, 4).End(xlUp)
        .Range("A9:" & Cells(org, c)).Sort _
        Key1:=.Range("D9"), Order1:=xlAscending, Orientation:=xlLeftToRight
    End With




End Sub
 
Got it. For anyone else.
Code:
With Sheets("RGA Data")
                .Range(.Cells(9, 4), .Cells(org, c)).Sort _
                Key1:=.Range("D9"), Order1:=xlDescending, Orientation:=xlLeftToRight
            End With
[CODE]
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top