PDA

View Full Version : Autosort Range



jmenche
10-25-2005, 07:32 AM
Hi,

I have two input cells on a worksheet. I would like to sort a range automatically if one of these values changes. The worksheet_selectionchange method would sort it every time someone just clicked the cell. I see that there is a worksheet_change method. Can someone help me out?

Thanks

alimcpill
10-25-2005, 07:56 AM
I'm not sure exactly what you mean, but it might be this. As I understand it you want to use the worksheet_change event, but you don't know how to work out exactly where the change occured??


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Or Target.Address = "$B$1" Then
Me.Range("A2:E100").Sort Me.Range("A2")
End If
End Sub


Place the above code in the module of the worksheet you want to have this behaviour.
The above code says that if cell A1 or B1 is changed, the range A2:E100 will be sorted by column A. If this isn't quite what you're after , you may be able to work from this example?

Sorry if I've grabbed completely the wrong end of the stick...

jmenche
10-25-2005, 08:22 AM
Thanks!

You were right on the $. I was already playing around with it until I realized that I needed to capitalize my range address. Damn syntax!!