IF THEN with userform

jonathann3891

Board Regular
Joined
Apr 27, 2015
Messages
109
I have an if statement that checks the value of a certain cell before running the macro.

I want userform3 to hide or unload BEFORE showing the MsgBox.

Code:
If Sheets("PML").Range("E3").Value = "" ThenUserForm3.Hide
MsgBox "SELECT PILE SIZE", vbOKOnly, "MISSING DATA"
Userform1.Show
Else
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi,
Although I don't see full code I think you should use modeless when open UserForm3:

Code:
UserForm3.Show vbModeless

In this case "UserForm3.Hide" will work.

I hope that helps.

Regards,
 
Upvote 0
That should say

Code:
If Sheets("PML").Range("E3").Value = "" Then
UserForm3.Hide
MsgBox "SELECT PILE SIZE", vbOKOnly, "MISSING DATA"
Userform1.Show
Else
 
Upvote 0
Hi,
Although I don't see full code I think you should use modeless when open UserForm3:

Code:
UserForm3.Show vbModeless

In this case "UserForm3.Hide" will work.

I hope that helps.

Regards,

I think all my userforms should be modal. I dont want the user to do anything else until they click "OK" or "CANCEL"
 
Upvote 0
Hi,

Where did you put your code? If I add it to a module it doesn't work with modal userform. However if I assign code e.g. to a command button on Userform3 it works. Example:

Code:
Private Sub CommandButton1_Click()


If Sheets("PML").Range("E3").Value = "" Then
    UserForm3.Hide
    MsgBox "SELECT PILE SIZE", vbOKOnly, "MISSING DATA"
    UserForm1.Show
Else


End If


End Sub
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,048
Members
448,543
Latest member
MartinLarkin

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