Prevent event macro from executing on ALT-Enter

J

John Keith

I have the following worksheet change event macro and it works pretty
much as desired (description of macro at bottom of posting).

The macro is triggered as expected when the Enter key is pressed.

But..... the macro is also triggered when ALT-Enter is pressed, when I
want to enter a line feed into the text going into a cell but I'm not
done entering all of the text yet for that cell.

Is there a way I can get the macro to not trigger on the ALT-Enter key
event?

Private Sub Worksheet_Change(ByVal Target As Range)
a = Target.row
b = Target.Column
If b < 19 Or b > 28 Then Exit Sub
ColumnLetter = Left(Cells(1, b).Address(0, 0), 2 + (b <= 26))
Application.EnableEvents = False ' turn off to prevent looping
Cells(a, 2) = Format(Now(), "mm/dd/yy")
If b = 4 Then GoTo do_not_update
Current_Text = Cells(a, 4)
If Len(Current_Text) > 0 Then Current_Text = Chr(10) &
Current_Text
New_Text = " column " & ColumnLetter & " changed"
Cells(a, 4) = Format(Now(), "m/d/yy") & New_Text & Current_Text
Application.EnableEvents = True
End Sub

What the macro does:

If data is entered into cells in columns 19 thorugh 27 then add a text
note to the cell in column 4 of the same row indicating that column T
changed (for example).
John Keith
(e-mail address removed)
 
D

Dave Peterson

Alt-enter should cause this event to fire.

You sure that you're not seeing a compile error (where's that do_not_update
label????).
 
J

John Keith

On Mon, 13 Jul 2009 20:22:34 -0500, Dave Peterson


Dave,
Alt-enter should cause this event to fire.

OK, bummer, that's not ideal but I guess I'll have to deal with it.
You sure that you're not seeing a compile error (where's that do_not_update
label????).

Ooops, I edited the macro I posted a little to eliminate some
extraneous stuff that wasn't needed to explain the issue and I didn't
catch that. Good eyes! That was the test needed to prevent an infinite
loop from starting.



John Keith
(e-mail address removed)
 
D

Dave Peterson

That was a typo!!!!!

alt-enter should ****NOT**** cause this event to fire.

(stupid brain to fingers connection!!!)

You sure that you're editing the cell when you hit the alt-enter, right???
 
J

John Keith

That was a typo!!!!!
alt-enter should ****NOT**** cause this event to fire.

OK, that seems logical to me since I don't think the cell contents are
updated when ALT-Enter is pressed, that doesn't happen until Enter is
pressed.
(stupid brain to fingers connection!!!)

Happens to me all the time.
You sure that you're editing the cell when you hit the alt-enter, right???

Well I think so. Text similar to this is being entered:

Changes since last revision:
- change #1
- change #2
- change #3

ALT-Enter is used to start each bullet item and then when the cell
that the macro modifies during the event it will have multiple entries
of the form "7/10/09 column AA changed", one entry for each time
ALT-Enter is pressed. I need to go back to my friend who showed me the
problem but from what I saw this is an accurate description of the
problem he noted.

John Keith
(e-mail address removed)
 
D

Dave Peterson

I've never seen this happen.

I'd ask the friend to try to duplicate it once more.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top