ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If a value exists in a range (https://www.excelbanter.com/excel-programming/383111-if-value-exists-range.html)

jeffbert

If a value exists in a range
 
I am trying to have VBA evaluate the range C3:C100 (name defined as
Type_of_change), and if the value "TEST" exists in any one of those cells,
call Macro A, if not, Call Macro B. How do I get VBA to evaluate the range?

Thanks
Jeff


Gary''s Student

If a value exists in a range
 
Sub jeffbert()
Set r = Range("C3:C10")
wellisit = False
For Each rr In r
If InStr(rr.Value, "TEST") 0 Then
wellisit = True
Else
End If
Next
If wellisit Then
Call macroa
Else
Call macrob
End If
End Sub
--
Gary''s Student
gsnu200705


"jeffbert" wrote:

I am trying to have VBA evaluate the range C3:C100 (name defined as
Type_of_change), and if the value "TEST" exists in any one of those cells,
call Macro A, if not, Call Macro B. How do I get VBA to evaluate the range?

Thanks
Jeff


Tom Ogilvy

If a value exists in a range
 
if application.Countif(Range("C3:C100"),"Test") 0 then
MacroA
else
MacroB
End if

if test is not the sole value of the cell then

if application.Countif(Range("C3:C100"),"*Test*") 0 then
MacroA
else
MacroB
End if

--
Regards,
Tom Ogilvy


"jeffbert" wrote in message
...
I am trying to have VBA evaluate the range C3:C100 (name defined as
Type_of_change), and if the value "TEST" exists in any one of those cells,
call Macro A, if not, Call Macro B. How do I get VBA to evaluate the
range?

Thanks
Jeff





All times are GMT +1. The time now is 07:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com