ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   macro wants to exit excel (https://www.excelbanter.com/excel-discussion-misc-queries/94567-macro-wants-exit-excel.html)

curlydave

macro wants to exit excel
 
I don't know why but this macro wants to exit excel when I run it

Sub resetpage()
Range("A3:S20").Select
Selection.ClearContents
Range("A3").Select
userform1.Hide


End Sub
I have userform1.hide because I have a worksheetchange event that goes
like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Column = 1 Then
userform1.Show False
myRow = Target.Row
End If
End Sub

When I run Sub resetpage()
it clears the contents and then asks if I want to save changes as if I
had clicked exit

Why is this now happening? it doesn't happen all the time ,but it
happens alot


Dave Peterson

macro wants to exit excel
 
I don't see anything that would make excel want to quit.

But can you disable events before you clear the contents?

Sub resetpage()
Range("A3:S20").Select
application.enableevents = false
Selection.ClearContents
application.enableevents = true
Range("A3").Select
userform1.Hide
End Sub

This'll stop the worksheet_change event from firing. Is that what you want?

curlydave wrote:

I don't know why but this macro wants to exit excel when I run it

Sub resetpage()
Range("A3:S20").Select
Selection.ClearContents
Range("A3").Select
userform1.Hide

End Sub
I have userform1.hide because I have a worksheetchange event that goes
like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Column = 1 Then
userform1.Show False
myRow = Target.Row
End If
End Sub

When I run Sub resetpage()
it clears the contents and then asks if I want to save changes as if I
had clicked exit

Why is this now happening? it doesn't happen all the time ,but it
happens alot


--

Dave Peterson

curlydave

macro wants to exit excel
 
Thanks Dave,
The problem seems to be the userform1.hide
I therefore changed the worksheetchangecode to

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
myRow = Target.Row

If Union(Range("$A3:$A20"), Target).Address = Range("$A3:$A20").Address
Then
If Target = "" Then
UserForm1.Hide
Else: UserForm1.Show False
End If
End If

End Sub
this seems to have solved the problem......
Dave Peterson wrote:
I don't see anything that would make excel want to quit.

But can you disable events before you clear the contents?

Sub resetpage()
Range("A3:S20").Select
application.enableevents = false
Selection.ClearContents
application.enableevents = true
Range("A3").Select
userform1.Hide
End Sub

This'll stop the worksheet_change event from firing. Is that what you want?

curlydave wrote:

I don't know why but this macro wants to exit excel when I run it

Sub resetpage()
Range("A3:S20").Select
Selection.ClearContents
Range("A3").Select
userform1.Hide

End Sub
I have userform1.hide because I have a worksheetchange event that goes
like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Column = 1 Then
userform1.Show False
myRow = Target.Row
End If
End Sub

When I run Sub resetpage()
it clears the contents and then asks if I want to save changes as if I
had clicked exit

Why is this now happening? it doesn't happen all the time ,but it
happens alot


--

Dave Peterson



Dave Peterson

macro wants to exit excel
 
Glad you got it working.

curlydave wrote:

Thanks Dave,
The problem seems to be the userform1.hide
I therefore changed the worksheetchangecode to

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
myRow = Target.Row

If Union(Range("$A3:$A20"), Target).Address = Range("$A3:$A20").Address
Then
If Target = "" Then
UserForm1.Hide
Else: UserForm1.Show False
End If
End If

End Sub
this seems to have solved the problem......
Dave Peterson wrote:
I don't see anything that would make excel want to quit.

But can you disable events before you clear the contents?

Sub resetpage()
Range("A3:S20").Select
application.enableevents = false
Selection.ClearContents
application.enableevents = true
Range("A3").Select
userform1.Hide
End Sub

This'll stop the worksheet_change event from firing. Is that what you want?

curlydave wrote:

I don't know why but this macro wants to exit excel when I run it

Sub resetpage()
Range("A3:S20").Select
Selection.ClearContents
Range("A3").Select
userform1.Hide

End Sub
I have userform1.hide because I have a worksheetchange event that goes
like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Column = 1 Then
userform1.Show False
myRow = Target.Row
End If
End Sub

When I run Sub resetpage()
it clears the contents and then asks if I want to save changes as if I
had clicked exit

Why is this now happening? it doesn't happen all the time ,but it
happens alot


--

Dave Peterson


--

Dave Peterson


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com