Find Text in Range

ddub25

Well-known Member
Joined
Jan 11, 2007
Messages
617
Office Version
  1. 2019
Platform
  1. Windows
How would I write VBA code to do the following:

IF "P1" is evident in Range CX85:CX94 Then
Return "Place..." in CN73
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Assuming that P1 is text and, when present, is the only text in the cell...
Code:
[table="width: 500"]
[tr]
	[td]If Application.CountIf(Range("CX85:CX94"), "P1") Then Range("CN73").Value = "Place..."[/td]
[/tr]
[/table]
 
Upvote 0
Thanks Rick. How do I adapt it further to add the condition that "P2" cannot be evident in the range?

If Application.CountIf(Range("CX85:CX94"), "P1")

And Application.CountIf(Range("CX85:CX94"), DOES NOT CONTAIN "P2")

Then Range("CN73").Value = "Place..."
 
Upvote 0
Code:
If Application.CountIf(Range("CX85:CX94"), "P1") And Application.CountIf(Range("CX85:CX94"), "P2") = 0 Then Range("CN73").Value = "Place..."
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,892
Members
449,194
Latest member
JayEggleton

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