Forum Discussion
webbsinferno
Aug 20, 2020Copper Contributor
Auto Sort When Data Changes
Hello, I'm building an excel spreadsheet to track my investments and I have the spreadsheet ordered based on overall % of my portfolio, where the largest position is at the top and smallest at t...
NikolinoDE
Aug 20, 2020Platinum Contributor
It would be very helpful if a file always attached to the questions asked (without sensitive data), so that you can reach your goal faster and we will answer faster. a win-win situation. So you have to guess ... personally I was never good at that.
I will still try to help 🙂
Here is a macro as an example.
Private Sub Worksheet_Change(ByVal Target As Range)
Range("A2:I32").Sort Key1:=Range("D8:D32"), Order1:=xlDescending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End Sub
I would be happy to find out if I could help.
Nikolino
I know I don't know anything (Socrates)
NikolinoDE
Aug 20, 2020Platinum Contributor
Sorry previous VBA macro is for date cells. For this / with cell range selection
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A5:A300")) Is Nothing Then
Range("A5:G300").Sort Key1:=Range("A5"), _
Order1:=xlAscending, _
Header:=xlNo
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A5:A300")) Is Nothing Then
Range("A5:G300").Sort Key1:=Range("A5"), _
Order1:=xlAscending, _
Header:=xlNo
End If
End Sub