ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   automatically sorting a simple list (https://www.excelbanter.com/excel-discussion-misc-queries/136122-automatically-sorting-simple-list.html)

cbguy

automatically sorting a simple list
 
This seems like it should be simple, but I'm not having luck figuring out how
to do it. Any help would be appreciated. I have a simple list of 10 things
each with a value associated with it. As the values change, I'd like the
list to automatically resort itself in ascending order. I don't want to have
to go and highlight the two columns and use the sort command every time I
change one of the values. This should be easy right??? help.
--
Thanks, CBguy

Toppers

automatically sorting a simple list
 
Right-click on w/sheet tab (where your data is) "View code", and copy/paste
code below. If Column B .. no check for rows ...is changed, it sorts (by
column B) values.

HTH



Sub Worksheet_Change(ByVal target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False

If target.Column < 2 Then Exit Sub

Columns("A:B").Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ws_exit:
Application.EnableEvents = True

End Sub

"cbguy" wrote:

This seems like it should be simple, but I'm not having luck figuring out how
to do it. Any help would be appreciated. I have a simple list of 10 things
each with a value associated with it. As the values change, I'd like the
list to automatically resort itself in ascending order. I don't want to have
to go and highlight the two columns and use the sort command every time I
change one of the values. This should be easy right??? help.
--
Thanks, CBguy


cbguy

automatically sorting a simple list
 
Hey, that works great. Thanks for the help. : )
--
Thanks, CBguy


"Toppers" wrote:

Right-click on w/sheet tab (where your data is) "View code", and copy/paste
code below. If Column B .. no check for rows ...is changed, it sorts (by
column B) values.

HTH



Sub Worksheet_Change(ByVal target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False

If target.Column < 2 Then Exit Sub

Columns("A:B").Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ws_exit:
Application.EnableEvents = True

End Sub

"cbguy" wrote:

This seems like it should be simple, but I'm not having luck figuring out how
to do it. Any help would be appreciated. I have a simple list of 10 things
each with a value associated with it. As the values change, I'd like the
list to automatically resort itself in ascending order. I don't want to have
to go and highlight the two columns and use the sort command every time I
change one of the values. This should be easy right??? help.
--
Thanks, CBguy



All times are GMT +1. The time now is 07:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com