Show userform on macro

Dave Punky

Board Regular
Joined
Jan 7, 2010
Messages
133
Hi all,

I've created a Form / dialogue box (called Error) in VBA and I want this to display if a cell on my workbook is empty via a macro. I also need it to run another macro if these circumstances are not met.

Essentially what I have is:

If Range("A1").Value = 0 Then
Show Form (Error)
Else
Run Macro1
End If

I'm not sure exactly how I'm supposed to word this as all my attempts have failed. Can anybody provide any assistance in regards to this.

I'm running Excel 2003 for reference and literally my dialogue box has nothing to it.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I would call the form something other than just Error as I think it's a VBA reserved word. Maybe ErrorForm and then the code would be something like:

Code:
If Range("A1").Value = 0 Then
ErrorForm.Show
Else
Call Macro1
End If

Dom
 
Upvote 0
Thanks Domski that did the trick - Error for the name didn't seem to cause an issue but I changed the name just to be on the safe side.

In advancement to this, is there a way of having multiple if statements as I need to add another field if several conditions are not met, so basically mutiple IF statements all leading to the same conclusion - I can't remember exactly what I'm supposed to do. This is what I now need to do:

If Range("A1").Value = 0 Then
Form1.Show

If Range("A2").Value = 0 & Range("A3").Value = "Text" Then
Form2.Show
Range("A3").FormulaR1C1 = "NewText"
Else
Call Macro1

End If

I'm pretty sure theres a way of doing this, but it's not called IF it's some other statement. Any ideas?
 
Upvote 0
I'm gonna bump this - hopefully someone will see it and have some idea what I'm trying to do!
 
Upvote 0
Thanks Domski that did the trick - Error for the name didn't seem to cause an issue but I changed the name just to be on the safe side.

In advancement to this, is there a way of having multiple if statements as I need to add another field if several conditions are not met, so basically mutiple IF statements all leading to the same conclusion - I can't remember exactly what I'm supposed to do. This is what I now need to do:

If Range("A1").Value = 0 Then
Form1.Show
If Range("A2").Value = 0 & Range("A3").Value = "Text" Then
Form2.Show
Range("A3").FormulaR1C1 = "NewText"
Else
Call Macro1
End If

I'm pretty sure theres a way of doing this, but it's not called IF it's some other statement. Any ideas?



You're probably thinking about SelectCase, but IF will work.

If Range("A1").Value = 0 Then
Form1.Show
Else
If Range("A2").Value = 0 & Range("A3").Value = "Text" Then
Form2.Show
Else
If Range("A3").FormulaR1C1 = "NewText" Then
Call Macro1
End If
End If
End If
 
Last edited:
Upvote 0
Try this:

Code:
Sub Macro1()
    
    If Range("A1").Value = 5 Then
        Form1.Show
    ElseIf Range("A2").Value = 0 And Range("A3").Value = "Text" Then
        Form2.Show
    ElseIf Range("A3").Value = "NewText" Then
        Call Macro1
    End If

End Sub
 
Upvote 0
Thanks guys, both worked but I ended up using Trebor's as it's got a lot less statements at the end.

Very much appreciated for all the support!
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,657
Members
449,462
Latest member
Chislobog

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