Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default How to reset macro to run again after error ?

Sometimes when i get type mismatch error while running macro excel shows
error messege box and then opens vb code section and then i have to click
[end]. After that macro won't trigger anymore. Is there any way to reset
macro trigerring without closing & reopening excel ? Cuz this is what i
ussualy do if i encounter this error.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to reset macro to run again after error ?

Do you mean event code? If so just type Application.EnableEvents = True in
the immediate window.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mikus" wrote in message
...
Sometimes when i get type mismatch error while running macro excel shows
error messege box and then opens vb code section and then i have to click
[end]. After that macro won't trigger anymore. Is there any way to reset
macro trigerring without closing & reopening excel ? Cuz this is what i
ussualy do if i encounter this error.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default How to reset macro to run again after error ?

This is the code that creates type mismatch error.
Fow examle if i try to delete entire row or copy entire row... and so on

As you can see i already have "Application.EnableEvents = True"

Sub Worksheet_Change(ByVal Target As Range)
25
If Target.Column = 1 And Target.Value = "Priv" Then
'Range(Cells(Target.Row, 2), Cells(Target.Row, 3)).Value = "-"
Cells(Target.Row, 2).Value = "-"
Cells(Target.Row, 3).Select
Else
'Whatever original value or formulae for B and C
End If
Application.EnableEvents = True
End Sub

"Bob Phillips" wrote:

Do you mean event code? If so just type Application.EnableEvents = True in
the immediate window.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mikus" wrote in message
...
Sometimes when i get type mismatch error while running macro excel shows
error messege box and then opens vb code section and then i have to click
[end]. After that macro won't trigger anymore. Is there any way to reset
macro trigerring without closing & reopening excel ? Cuz this is what i
ussualy do if i encounter this error.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default How to reset macro to run again after error ?

Mikus. I warned you earlier to stay away from this event with the worksheet
you were developing. But it seems you are plunging head-first into it
anyway. What is happening? If the activecell is in column A and the value =
"Priv", Then the code that follows is going to run. If you delete the entire
row then the cells are gone that the code was looking to do something with.
Bingo, Runtime Error. Similarly with a copy. The copy is giving those cells
one value while the code is trying to give it another. Mixed messages to the
same cells gets a Runtime Error.
The workaround is to further limit the code from running when you don't want
it to. You have so far limited it to the entire column of A (do you really
need all 65,536 rows?) plus only if that cell = "Priv". Now you need to
limit the number of cells that are in Target before the code should run.
When you select an entire row , then Target As Range has 256 cells in it.
You need to tell the Event NOT to run if there is more than 1 cell in
Target.

Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
'Your code
End Sub

This will kill the code whenever more than 1 cell is selected.
If you want to further restrict the code to only some cells in column A,
then say so, and we can deal with that.

Mike F

"Mikus" wrote in message
...
This is the code that creates type mismatch error.
Fow examle if i try to delete entire row or copy entire row... and so on

As you can see i already have "Application.EnableEvents = True"

Sub Worksheet_Change(ByVal Target As Range)
25
If Target.Column = 1 And Target.Value = "Priv" Then
'Range(Cells(Target.Row, 2), Cells(Target.Row, 3)).Value = "-"
Cells(Target.Row, 2).Value = "-"
Cells(Target.Row, 3).Select
Else
'Whatever original value or formulae for B and C
End If
Application.EnableEvents = True
End Sub

"Bob Phillips" wrote:

Do you mean event code? If so just type Application.EnableEvents = True
in
the immediate window.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mikus" wrote in message
...
Sometimes when i get type mismatch error while running macro excel
shows
error messege box and then opens vb code section and then i have to
click
[end]. After that macro won't trigger anymore. Is there any way to
reset
macro trigerring without closing & reopening excel ? Cuz this is what i
ussualy do if i encounter this error.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to reset macro to run again after error ?

Yes but you said it happened after an error in the macro, so I was
suggesting doing it in teh VBE to reset events.

Seeing the code though I don't know where the events get turned off. And
where did Private go in the event declaration?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mikus" wrote in message
...
This is the code that creates type mismatch error.
Fow examle if i try to delete entire row or copy entire row... and so on

As you can see i already have "Application.EnableEvents = True"

Sub Worksheet_Change(ByVal Target As Range)
25
If Target.Column = 1 And Target.Value = "Priv" Then
'Range(Cells(Target.Row, 2), Cells(Target.Row, 3)).Value = "-"
Cells(Target.Row, 2).Value = "-"
Cells(Target.Row, 3).Select
Else
'Whatever original value or formulae for B and C
End If
Application.EnableEvents = True
End Sub

"Bob Phillips" wrote:

Do you mean event code? If so just type Application.EnableEvents = True

in
the immediate window.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mikus" wrote in message
...
Sometimes when i get type mismatch error while running macro excel

shows
error messege box and then opens vb code section and then i have to

click
[end]. After that macro won't trigger anymore. Is there any way to

reset
macro trigerring without closing & reopening excel ? Cuz this is what

i
ussualy do if i encounter this error.








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default How to reset macro to run again after error ?

Thank you Mike!

"Mike Fogleman" wrote:

Mikus. I warned you earlier to stay away from this event with the worksheet
you were developing. But it seems you are plunging head-first into it
anyway. What is happening? If the activecell is in column A and the value =
"Priv", Then the code that follows is going to run. If you delete the entire
row then the cells are gone that the code was looking to do something with.
Bingo, Runtime Error. Similarly with a copy. The copy is giving those cells
one value while the code is trying to give it another. Mixed messages to the
same cells gets a Runtime Error.
The workaround is to further limit the code from running when you don't want
it to. You have so far limited it to the entire column of A (do you really
need all 65,536 rows?) plus only if that cell = "Priv". Now you need to
limit the number of cells that are in Target before the code should run.
When you select an entire row , then Target As Range has 256 cells in it.
You need to tell the Event NOT to run if there is more than 1 cell in
Target.

Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
'Your code
End Sub

This will kill the code whenever more than 1 cell is selected.
If you want to further restrict the code to only some cells in column A,
then say so, and we can deal with that.

Mike F

"Mikus" wrote in message
...
This is the code that creates type mismatch error.
Fow examle if i try to delete entire row or copy entire row... and so on

As you can see i already have "Application.EnableEvents = True"

Sub Worksheet_Change(ByVal Target As Range)
25
If Target.Column = 1 And Target.Value = "Priv" Then
'Range(Cells(Target.Row, 2), Cells(Target.Row, 3)).Value = "-"
Cells(Target.Row, 2).Value = "-"
Cells(Target.Row, 3).Select
Else
'Whatever original value or formulae for B and C
End If
Application.EnableEvents = True
End Sub

"Bob Phillips" wrote:

Do you mean event code? If so just type Application.EnableEvents = True
in
the immediate window.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mikus" wrote in message
...
Sometimes when i get type mismatch error while running macro excel
shows
error messege box and then opens vb code section and then i have to
click
[end]. After that macro won't trigger anymore. Is there any way to
reset
macro trigerring without closing & reopening excel ? Cuz this is what i
ussualy do if i encounter this error.






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
Need Macro to reset dependent list Bean Counter[_2_] Excel Discussion (Misc queries) 2 May 12th 10 06:07 PM
Reset Macro Pastel Hughes Excel Discussion (Misc queries) 1 April 24th 06 10:41 PM
I need a macro that will reset cells to zero Macro Beginner Excel Programming 2 August 26th 05 07:49 PM
On Error reset? PCLIVE Excel Programming 2 March 5th 04 10:13 PM
reset drop-down menus with macro Sebastian Axelsson Excel Programming 0 March 5th 04 09:41 AM


All times are GMT +1. The time now is 12:08 PM.

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"