View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default Macro triggered by an event

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B:B" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Me.Cells(.Row, "A").Value = Me.Cells(.Row - 1, "A").Value + 1
Me.Range("A:G").Sort key1:=Me.Range("B1"), header:=xlYes
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

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Mekinnik" wrote in message
...
I have a worksheet that I am storing a list of manufacturers and there
addresses and phone info in, I have it set up this way.

A B C D E
F G
1 sequence ManName Address City State Zip
Phone
2 1 john doe 111 doe rd. nowhere AA 00000
(000)0000-0000
3 2 xxxxx xxxxxx xxxx xx
xxxxxx xxxxxxxxxxxxxx

Now I would like the macro to fire when I type the ManName into the cell
and
create(autofill) cell A2 and on with the next sequencial number. In
addition
to that I would like the same macro to fire sorting the ManName column
keeping all the info with the sequence number when the worksheet is
closed.