An If Question in VBA

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
764
Office Version
  1. 2016
Platform
  1. Windows
I've wrote this to check a cell for one of two words. It will look for one word, but how do I make it look for either word? Calc being a macro! Am I on the right track?

If Range("B1").Value = "First" Then Calc
If Range("B1").Value = "Second" Then Calc
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
in spreadsheet in C1 type
=if(or(B1="first",b1="second" ),"yes","no")

in vba
if range("B1")="first" or range("B1")="second" then
.................
....................
 

njimack

Well-known Member
Joined
Jun 17, 2005
Messages
7,764
No need for the formula in C1. Simply use the following code:

Code:
If Range("B1").Value = "First" or Range("B1").Value = "Second" Then Calc
 

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
764
Office Version
  1. 2016
Platform
  1. Windows
Thanks

A big thank you to both of you who offered help. It works perfectly.
 

Forum statistics

Threads
1,136,309
Messages
5,674,999
Members
419,541
Latest member
freddyboots

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