LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
dsi dsi is offline
external usenet poster
 
Posts: 6
Default loop replacement of multiple if-then's

I have some very weird problems, i must be missing something easy but i
have been at it for some time...
the following code is where I can isolate the diffrent behaviours
I assume that uncommenting solution 1 should result in the same
behaviour as uncommenting Solution 2 (with more robustness) but
instead, Solution 1 results in Message section 1 not appearing, the
Msgtest appearing over and over (infinite loop) and Message3-5 not
appearing. If I use Solution 2 I get code that works and does exactly
what I need except it isn't scalable (ie only checks 4 times) and all
messages appear as expected.

<code
For RowIndex = rowstart To rowend

Set c = Selection.Find()

'Message section 1:
Message = MsgBox(c.Value, vbInformation)
Message1 = MsgBox(Cells(c.Row, colPrimary).Value, vbInformation)
Message2 = MsgBox(Cells(c.Row, colPrimary).Value = "P",
vbInformation)


'Solution 1:
' Do Until (Cells(c.Row, colPrimary).Value = "P")
' Msgtest = MsgBox("testing", vbInformation)
' Set c = Cells(c.Row + 1, c.Column)
' Message3 = MsgBox(c.Value, vbInformation)
' Message4 = MsgBox(Cells(c.Row, colPrimary).Value,
vbInformation)
' Message5 = MsgBox(Cells(c.Row, colPrimary).Value = "P",
vbInformation)
' Loop

' Solution 2
' If (Cells(c.Row, colPrimary).Value < "P") Then
' Set c = Cells(c.Row + 1, c.Column)
' Message3 = MsgBox(c.Value, vbInformation)
' Message4 = MsgBox(Cells(c.Row, colPrimary).Value,
vbInformation)
' Message5 = MsgBox(Cells(c.Row, colPrimary).Value = "P",
vbInformation)
' End If
' If (Cells(c.Row, colPrimary).Value < "P") Then
' Set c = Cells(c.Row + 1, c.Column)
' Message3 = MsgBox(c.Value, vbInformation)
' Message4 = MsgBox(Cells(c.Row, colPrimary).Value,
vbInformation)
' Message5 = MsgBox(Cells(c.Row, colPrimary).Value = "P",
vbInformation)
' End If
' If (Cells(c.Row, colPrimary).Value < "P") Then
' Set c = Cells(c.Row + 1, c.Column)
' Message3 = MsgBox(c.Value, vbInformation)
' Message4 = MsgBox(Cells(c.Row, colPrimary).Value,
vbInformation)
' Message5 = MsgBox(Cells(c.Row, colPrimary).Value = "P",
vbInformation)
' End If
' If (Cells(c.Row, colPrimary).Value < "P") Then
' Set c = Cells(c.Row + 1, c.Column)
' Message3 = MsgBox(c.Value, vbInformation)
' Message4 = MsgBox(Cells(c.Row, colPrimary).Value,
vbInformation)
' Message5 = MsgBox(Cells(c.Row, colPrimary).Value = "P",
vbInformation)
' End If

Next RowIndex
</code

 
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
Excel If/Then's [email protected] Excel Worksheet Functions 6 March 8th 07 08:12 PM
If Then's for 12 textboxes to check if they are empty. Beertje Excel Discussion (Misc queries) 3 October 27th 05 02:34 PM
Need help mith multiple IF Then's Matt[_33_] Excel Programming 2 October 22nd 05 01:49 AM
conditional if then's Jimc Excel Programming 5 May 21st 05 03:17 PM
multiple cells in a loop jmorgs[_3_] Excel Programming 1 August 30th 04 04:24 PM


All times are GMT +1. The time now is 03:15 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"