close userform runs twice

davidmyers

Board Regular
Joined
Jan 29, 2017
Messages
88
Office Version
  1. 2016
Platform
  1. Windows
Hi I have the following code
Code:
Private Sub CloseBtn_Click()
ActiveCell.EntireRow.Font.ColorIndex = 1
Unload UserForm4
MsgBox "closing"
End Sub

Can someone suggest a reason that it runs twice - I click Close, the form disappears, message box "closing" appears, then the form appears again, click Close, the form closes and the message box "closing" appears, click "ok". Why does the routine run twice?

I have other userforms on the same sheet that close without any problem

Thanks for any help
David
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi, thanks for your response.
I removed the message altogether and tried this

Code:
Option Explicit
Dim boolRunOnce As Boolean


Private Sub CloseBtn_Click()
If boolRunOnce = False
   boolRunOnce = True
   ActiveCell.EntireRow.Font.ColorIndex = 1
   Unload Me
End If
End Sub

But it still runs twice - that is I need to click Close twice.
I suspect the problem is somewhere else and not in the CloseBtn_Click routine.
Any ideas?

Thanks
David
 
Upvote 0
Not really. If there's other code related to this, post it here and someone can take a look at it...see what they/we think.
 
Upvote 0
Thanks for your help,
Found the problem - in code for the sheet I opened the same form twice - and so had to close it twice - sorry to have wasted your time.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top