Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default Events don't seem to trigger after deleting cell values

I have a workbook with the following code in a sheet:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo errHandler
Application.EnableEvents = False
If Target.Count 1 Then Exit Sub
If Right(Target.Address, 2) = "$1" Then Exit Sub
With Me
If Left(Target.Address, 3) = "$A$" Then
With Target.Cells.Offset(0, 1)
.FormulaR1C1 =
"=IF(ISNA(IF(ISBLANK(RC[-1]),"""",VLOOKUP(RC[-1],SAPplantno,
2,FALSE)))," & _
"""Plant Description not found."",
(IF(ISBLANK(RC[-1]),"""",VLOOKUP(RC[-1],SAPplantno,2,FALSE))))"
.Value = .Value
End With
'MsgBox Target.Address & " a"
ElseIf Left(Target.Address, 3) = "$C$" Then
With Target.Cells.Offset(0, 1)
.FormulaR1C1 =
"=IF(ISBLANK(RC[-1]),"""",IF(ISNA(VLOOKUP(RC[-1],matdesclu,2,FALSE)),"
& _
"""Description not found."",
(VLOOKUP(RC[-1],matdesclu,2,FALSE))))"
.Value = .Value
End With
'MsgBox Target.Address & " c"
ElseIf Left(Target.Address, 3) = "$D$" Then
With Target.Cells.Offset(0, -1)
.FormulaR1C1 =
"=IF(ISBLANK(RC[1]),"""",IF(ISNA(VLOOKUP(RC[1],MatNumlu,2,FALSE))," &
_
"""Description not found."",
(VLOOKUP(RC[1],MatNumlu,2,FALSE))))"
.Value = .Value
End With
'MsgBox Target.Address & " d"
ElseIf Left(Target.Address, 3) = "$F$" Then
With Target.Cells.Offset(0, 1)
.FormulaR1C1 =
"=IF(ISNA(IF(ISBLANK(RC[-1]),"""",VLOOKUP(RC[-1],SAPplantno,
2,FALSE)))," & _
"""Plant Description not found."",
(IF(ISBLANK(RC[-1]),"""",VLOOKUP(RC[-1],SAPplantno,2,FALSE))))"
.Value = .Value
End With
'MsgBox Target.Address & " f"
'Else
End If
End With
Application.EnableEvents = True

Exit Sub
errHandler:
MsgBox Err.Number & " " & Err.Description
End Sub

It all works great unless you go back and delete (clearcontents)
something out of multiple cells; then it seems like nothing will
trigger. (before save, before print etc.) No errors, no action. I've
tried manually setting enableevents to true (and in multiple events),
verifying targets and other things but it won't start working again
until I close and re-open the file. I feel like I may be overlooking
something simple. I think it has to do with exiting if the target
count is more than one, but leaving that out produces other
undesirable actions.

I really need to make automation as transparent as possible and limit
interactions/complexity as much as possible to the users.

A somewhat related double post: Whenever I have code in the beforesave
event and close the app with multiple workbooks open, the workbook(s)
won't close even if the code is as simple as me.save. Learned to live
with this one, but if anyone has an explanation, I'd be interested.

Thanks!
ward376
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default Events don't seem to trigger after deleting cell values

code didn't wrap right if you try it
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Events don't seem to trigger after deleting cell values

I bet the event fires when you update/clear multiple cells, but as soon as it
gets to this line:

If Target.Count 1 Then Exit Sub

The routine exits. And even worse, it exits with .enableevents = false. That
means that the event won't fire for the next change.

Try this order:

If Target.Count 1 Then Exit Sub
Application.EnableEvents = False

========
As for the second question, I'd guess that there was an error in the code--maybe
with events again???? I think you'll have to post some of the offending code
for anyone to really help.

ward376 wrote:

I have a workbook with the following code in a sheet:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo errHandler
Application.EnableEvents = False
If Target.Count 1 Then Exit Sub
If Right(Target.Address, 2) = "$1" Then Exit Sub
With Me
If Left(Target.Address, 3) = "$A$" Then
With Target.Cells.Offset(0, 1)
.FormulaR1C1 =
"=IF(ISNA(IF(ISBLANK(RC[-1]),"""",VLOOKUP(RC[-1],SAPplantno,
2,FALSE)))," & _
"""Plant Description not found."",
(IF(ISBLANK(RC[-1]),"""",VLOOKUP(RC[-1],SAPplantno,2,FALSE))))"
.Value = .Value
End With
'MsgBox Target.Address & " a"
ElseIf Left(Target.Address, 3) = "$C$" Then
With Target.Cells.Offset(0, 1)
.FormulaR1C1 =
"=IF(ISBLANK(RC[-1]),"""",IF(ISNA(VLOOKUP(RC[-1],matdesclu,2,FALSE)),"
& _
"""Description not found."",
(VLOOKUP(RC[-1],matdesclu,2,FALSE))))"
.Value = .Value
End With
'MsgBox Target.Address & " c"
ElseIf Left(Target.Address, 3) = "$D$" Then
With Target.Cells.Offset(0, -1)
.FormulaR1C1 =
"=IF(ISBLANK(RC[1]),"""",IF(ISNA(VLOOKUP(RC[1],MatNumlu,2,FALSE))," &
_
"""Description not found."",
(VLOOKUP(RC[1],MatNumlu,2,FALSE))))"
.Value = .Value
End With
'MsgBox Target.Address & " d"
ElseIf Left(Target.Address, 3) = "$F$" Then
With Target.Cells.Offset(0, 1)
.FormulaR1C1 =
"=IF(ISNA(IF(ISBLANK(RC[-1]),"""",VLOOKUP(RC[-1],SAPplantno,
2,FALSE)))," & _
"""Plant Description not found."",
(IF(ISBLANK(RC[-1]),"""",VLOOKUP(RC[-1],SAPplantno,2,FALSE))))"
.Value = .Value
End With
'MsgBox Target.Address & " f"
'Else
End If
End With
Application.EnableEvents = True

Exit Sub
errHandler:
MsgBox Err.Number & " " & Err.Description
End Sub

It all works great unless you go back and delete (clearcontents)
something out of multiple cells; then it seems like nothing will
trigger. (before save, before print etc.) No errors, no action. I've
tried manually setting enableevents to true (and in multiple events),
verifying targets and other things but it won't start working again
until I close and re-open the file. I feel like I may be overlooking
something simple. I think it has to do with exiting if the target
count is more than one, but leaving that out produces other
undesirable actions.

I really need to make automation as transparent as possible and limit
interactions/complexity as much as possible to the users.

A somewhat related double post: Whenever I have code in the beforesave
event and close the app with multiple workbooks open, the workbook(s)
won't close even if the code is as simple as me.save. Learned to live
with this one, but if anyone has an explanation, I'd be interested.

Thanks!
ward376


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default Events don't seem to trigger after deleting cell values

You're exactly right. Thank you very much!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting cell values watkincm Excel Programming 0 August 18th 06 02:55 PM
Recurring annual events using a specific date as a trigger date Bamboozled Excel Worksheet Functions 1 June 6th 05 01:44 PM
Re - Excel Loading Multiple Instances to Trigger Events amidst Switching-from-One-to-Another [email protected] Excel Programming 1 February 8th 05 12:36 AM
Time events to trigger VB (corrected) David Robinson[_3_] Excel Programming 6 November 19th 03 02:06 PM
Tim events to trigger VB programs David Robinson[_3_] Excel Programming 0 November 18th 03 09:42 PM


All times are GMT +1. The time now is 03:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"