Call Sub dependant on Cell Value

grady121

Active Member
Joined
May 27, 2005
Messages
381
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.

Fowmy

Well-known Member
Joined
Jul 10, 2008
Messages
512
Office Version
  1. 365
Platform
  1. Windows
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
 

grady121

Active Member
Joined
May 27, 2005
Messages
381
Office Version
  1. 2016
Platform
  1. Windows
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,746
Messages
5,833,448
Members
430,209
Latest member
addms

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
Top