Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Prevent event macro from executing on ALT-Enter
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Prevent event macro from executing on ALT-Enter
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????). John Keith wrote: 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 -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Prevent event macro from executing on ALT-Enter
On Mon, 13 Jul 2009 20:22:34 -0500, Dave Peterson
wrote: 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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Prevent event macro from executing on ALT-Enter
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??? John Keith wrote: On Mon, 13 Jul 2009 20:22:34 -0500, Dave Peterson wrote: 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 -- Dave Peterson |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Prevent event macro from executing on ALT-Enter
On Tue, 14 Jul 2009 07:32:24 -0500, Dave Peterson
wrote: 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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Prevent event macro from executing on ALT-Enter
I've never seen this happen.
I'd ask the friend to try to duplicate it once more. John Keith wrote: On Tue, 14 Jul 2009 07:32:24 -0500, Dave Peterson wrote: 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 -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VBA Debug Mode : How to I enter it after executing the nth data row. | Excel Programming | |||
need to modify a macro to prevent it from executing if in wrong area of the sheet | Excel Discussion (Misc queries) | |||
MsgBox in Enter event causes combobox not to run Change event | Excel Programming | |||
prevent UDF from executing | Excel Programming |