PDA

View Full Version : Solved: sort rows only when data is entered till column K



noobie
11-21-2006, 06:07 PM
:hi: all,

before posting this thread, i check alot on this forum. But apparently, none was so similar to what i wanted. So I would appreciate if anyone could provide any suggestions! : pray2:

I need a macro which sort my rows
- only when the data is entered from til column K (starts at column A).
- based on the first two columns.
- based on worksheet change



Private Sub Worksheet_Change(ByVal Target As Range)
Columns("A:B").Sort _
Key1:=Range("A:B"), Order1:=xlAscending, Header:=xlYes
End Sub




so after this is what i have modified! Pls help! Thanks everyone!

rbrhodes
11-21-2006, 07:19 PM
noobie,

You don't really give enough info but this might get this started.

1) If Col K changes then the macro fires

2) It sorts based on Col A then Col B



Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False

'Check that Col K changed
If Not Intersect(Target, Range("K:K")) Is Nothing Then

'Sort all rows A1 to changed cell. Key1 = Col A, Key2 = Col B
Range("A1:K" & Target.Row).Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _
, Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End If
Application.ScreenUpdating = True
End Sub


Cheers,

dr

noobie
11-21-2006, 07:53 PM
Right on! that was exactly what i needed!! :thumb

Thanks a million!! :yay