Thread: Sorting code
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Sorting code

Try some VBA event code

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B:B"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Columns("A:B").Sort key1:=Range("B1"), header:=xlNo
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"MarkN" wrote in message
...
Hello,

I am new to VBA and have what is probably quite a simple problem. I have a
two-column list that does not have column headers. The values in column 2
come are generated by links to other areas of sheet1 and change quite

often.
I have to keep resorting the list when a change occurs.

I would like to find the code that will automatically sort on column 2 of

my
range as values change.

--
Thanks in advance,
MarkN