Thank you so much. This worked I had to make a few changes. I needed to sort based on I2 so I changed it to
Range ("I2")
I needed sorted from largest to smallest so I changed it to:
Order:=xlDescending
I wanted the sum result go to the last row of data and overwrite what's in there so I changed it to:
Cells(lastrow, I).Value
I wanted to select row 2 to one row before the last line to sort a I have title in the row 1 an total in the last row :
.SetRange Range("A2:I" & lastrow -1)
So overall it looks like this:
[Dim was As Worksheet
Set wf = Application.WorksheetFunction
Set ws = ActiveWorkbook.ActiveSheet
For i = 3 To 8 'selecting column C to column H
lastrow = Cells(Rows.Count, i).End(xlUp).Row 'finds the lastrow
Cells(lastrow, i).Value = wf.Sum(Range(Cells(1, i), Cells(lastrow, i))) 'puts the sum on the first empty cell
If i = 7 Or i = 8 Then
Cells(lastrow, i).Select
Selection.NumberFormat = "$#,##0.00"
End If
Next i
'This is the sort portion of the macro, from the macro recorder
ws.Sort.SortFields.Clear
ws.Sort.SortFields.Add Key:=Range("I2"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ws.Sort
.SetRange Range("A2:I" & lastrow - 1)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub]
Also one thing I like to ask you is what is the code to select the last row of the data. I can use macro recorder to do the rest for me if I have the code for selecting the last row of the data.