stop a macro if it does not contain

  • Thread starter Thread starter Wildman
  • Start date Start date
W

Wildman

I have a macro that i would like to NOT to run (or stop) if it does
not contain the word "wildman" in a range A2:A30000 or if there is
no text in that range as well.

Thanks in advance
Wildman
 
Private Sub CommandButton1_Click()

If WorksheetFunction.CountIf(Range("A2:A30"), "wildman") < 1 Then
Exit Sub
End If

' continue your code here
End Sub

No need to check if range empty as if "wildman" not there then no need
to run macro.
I have a macro that i would like to NOT to run (or stop) if it does
not contain the word "wildman" in a range A2:A30000 or if there is
no text in that range as well.


Mangesh
 
nv test it out but shld be correct


Code:
--------------------
sub macro()

For each rngCell in activesheet.range(A2:A30000).cells

if rngCell.value="wildman" then
blnWildman=true
blnNotEmpty=true
exit for
elseif rngCell<>empty then
blnNotEmpty=true
exit for
end if

next rngCell

if blnWildman<>true and blnNotEmpty<>true then
Exit sub
end if

<macro code>

End Sub
 
OK, am I the only one wondering why the heck you're looking for a
wildman?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top