View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Mekinnik Mekinnik is offline
external usenet poster
 
Posts: 159
Default Macro triggered by an event

Mr. Phillips,
I cut and pasted your code as you said only when the macro fires it does
nothing and I cannot figure out why. I currently have 162 entries in my
worksheet and the macro does not create a sequence number for the in column A
at all. Now a couple of questions
1) the second line
Const WS_RANGE As String = "B:B" '<== change to suit
what does this line do and how do I call it?

2) In the following line is the word header supposed to be replaced with my
column header name?
Me.Range("A:G").Sort key1:=Me.Range("B1"), header:=xlYes

I understand most of the vb language however I am still learning and
teaching myself to use it. Maybe explain the code for me what it is suppose
to do line by line?

Sorry to be such a pain.

Thanks
Mekinnik

"Bob Phillips" wrote:

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.