Call Sub dependant on Cell Value

grady121

Active Member
Joined
May 27, 2005
Messages
383
Office Version
  1. 2016
Platform
  1. Windows
I have a userform with a Cmd button, when clicked I want it to call one of two Subs, depending on the value of Cell "A1".
At the moment it all works OK apart from the fact that If Range("A1") = "P" - its calling Code2. i.e. the wrong Sub ???
How do I reference "P" correctly?


If Range("A1") = "P" Then Call Code1
If Range("A1") <= "4" Then Call Code1

If Range("A1") >= "5" Then Call Code2


Any help to a Newbie appreciated.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Assuming Range("A1") has either 4,5, or "P" - Try this

Code:
If Range("A1") = "P" Or Range("A1") <= 4 Then
Call code1
ElseIf Range("a1") >= 5 Then
Call code2
End If
 
Upvote 0
Thanks Fowmy
Just what I needed.
I tried every which way but it seems I just "Couldn't see the Woods from the Tree's" - again.

Thanks for quick response.
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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