Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default stop a macro if it does not contain

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default stop a macro if it does not contain


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


--
mangesh_yadav
------------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...o&userid=10470
View this thread: http://www.excelforum.com/showthread...hreadid=375134

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default stop a macro if it does not contain

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default stop a macro if it does not contain

No you are not the only one.

"Nick Hebb" wrote in message
ups.com...
OK, am I the only one wondering why the heck you're looking for a
wildman?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default stop a macro if it does not contain


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
--------------------


--
d61helix
------------------------------------------------------------------------
d61helix's Profile: http://www.excelforum.com/member.php...o&userid=20090
View this thread: http://www.excelforum.com/showthread...hreadid=375134



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
stop a macro from being used Ber Excel Discussion (Misc queries) 3 April 26th 10 10:13 AM
Macro Stop LMP Excel Worksheet Functions 3 April 28th 08 07:33 PM
Macro: With Stop it works. Without Stop it doesn't. Don Wiss Excel Programming 2 October 12th 04 10:49 AM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM
How do I stop a macro Steve[_41_] Excel Programming 2 September 23rd 03 03:54 PM


All times are GMT +1. The time now is 01:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"