Sorting a column with dynamic data using VBA

I’ve want to sort this excel data by SUM in descending order but the SUM column has the formulas. When I use sort using the key C3, it won’t sort. How to sort a field like this?

You can use record a macro in excel using the Macro Recorder and call the macro using the Execute Macro Activity. Bellow the code I got from the Recorder:
Sub Macro1()

’ Macro1 Macro

ActiveWorkbook.Worksheets(“Planilha1”).Sort.SortFields.Add2 Key:=Range(“C2”) _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets(“Planilha1”).Sort
.SetRange Range(“A3:C6”)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
End With
End Sub

1 Like

Thank you!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.