Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default looping for a condition


I will try to explain this as best as possible. Beginning VBA user and
have excel 2003. What I would like to do is this.

I need code to look at a field in a row, for example

If activecell.offset(0,5).value = yes then
"msg box to ask a question if it wants to print out"
End If


My problem is the following.

I have sheet1

Row 20 = Original 4 oz
Row 21 = Original 9 oz
Row 22 = Original 20 oz
Row 23 = Original 48 oz


The code loops thru each row and checks to see if
activecell.offset(0,5).value = yes
If yes then it prompts for printout with a message box.

This works great if I only have 1 item.

But for the above situation I don't want the message box to prompt for
the printout until it has looped thru the last of the group (in this
case Original 48 oz). Then prompt for a message box


Sorry for the lousy explanations.


I would appreciate any help

thanks Josh


--
jhahes
------------------------------------------------------------------------
jhahes's Profile: http://www.excelforum.com/member.php...o&userid=23596
View this thread: http://www.excelforum.com/showthread...hreadid=472190

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default looping for a condition

Not sure why you are looping.

It sounds like if there is a single "yes" anywhere, than you want a
printout. For this you can use

If Worksheetfunction.Countif(Columns(ActiveCell.Colum n+5),"yes")0 then
' do your stuff
End If

or you can loop
Dim rw as Long
For rw = 20 to 23
If Cells(rw, 6).Text = "yes" then
'do your stuff
end if
Next

or
Dim cel as Range
For each cel in Range("F20:F23")
If cel = "yes" then
'do your stuff
end if
Next


for each loop you can set a variable x to 0 and keep adding to it

x = 0
For each
if "yes" then
x = x+1
end if
next

If x 0 then
' do your stuff
End if

A lot depends on how you are selecting the cell to test.

Post back...
--
steveB

Remove "AYN" from email to respond
"jhahes" wrote in
message ...

I will try to explain this as best as possible. Beginning VBA user and
have excel 2003. What I would like to do is this.

I need code to look at a field in a row, for example

If activecell.offset(0,5).value = yes then
"msg box to ask a question if it wants to print out"
End If


My problem is the following.

I have sheet1

Row 20 = Original 4 oz
Row 21 = Original 9 oz
Row 22 = Original 20 oz
Row 23 = Original 48 oz


The code loops thru each row and checks to see if
activecell.offset(0,5).value = yes
If yes then it prompts for printout with a message box.

This works great if I only have 1 item.

But for the above situation I don't want the message box to prompt for
the printout until it has looped thru the last of the group (in this
case Original 48 oz). Then prompt for a message box


Sorry for the lousy explanations.


I would appreciate any help

thanks Josh


--
jhahes
------------------------------------------------------------------------
jhahes's Profile:
http://www.excelforum.com/member.php...o&userid=23596
View this thread: http://www.excelforum.com/showthread...hreadid=472190



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
looping and stopping when a condition is met - test april Excel Discussion (Misc queries) 1 October 21st 09 11:36 PM
lookup with multiple condition, but one condition to satisfy is en Eddy Stan Excel Worksheet Functions 2 October 27th 07 02:06 PM
Looping till condition is satisfied? Jo[_2_] Excel Worksheet Functions 3 October 4th 07 09:43 PM
Condition 1 overules condition 2? Bultgren Excel Worksheet Functions 2 January 20th 06 12:29 PM
I need 4 condition for condition formatting SeeKY Excel Programming 2 June 7th 05 09:41 AM


All times are GMT +1. The time now is 02:30 AM.

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

About Us

"It's about Microsoft Excel"