LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Frustrating Boolean/loop iteration problem


Hello all, I'm having a problem with a loop. I have two columns (C and
D but I used activecell just to generalize) that contain dates. What I
need the loop to do is compare the pairs of dates in C and D, and
replace the date in C if the two dates are different. If D2 is blank
or the if the two dates are the same, it should just skip on to the
next pair of dates.

It seemed simple enough, but then the logic failed. If the first pair
of cells it evaluates don't match (cn2 = true) and the cell in column d
isn't blank (cn1 = true), then it works fine and sets cn3 to true. For
every iteration after the first, it sets cn2 to false regardless of
whether or not they match. It evaluates cn1 without a problem on each
iteration, i.e., if the cell in column d is empty then it has no
problem. It just seems to go "blind" every time after the first with
regards to matching dates. I tried debugging to see if for some reason
it was setting the dates to be the same each time, but it reads them
fine. Can anybody lend a hand on this? Code below:


Code:
--------------------
Sub test()

Dim cn1 As Boolean, cn2 As Boolean, cn3 As Boolean

cn1 = ActiveCell.Offset(0, 1).Value < Empty
cn2 = ActiveCell.Formula < ActiveCell.Offset(0, 1).Formula
cn3 = ((cn1 = True) And (cn2 = True))

Do

Debug.Print ActiveCell.Value
Debug.Print ActiveCell.Offset(0, 1).Value

If cn3 = True Then
ActiveCell.Formula = ActiveCell.Offset(0, 1).Formula
End If
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Offset(0, 1).Formula = "STOP"

End Sub
--------------------


Thanks!


--
carg1
------------------------------------------------------------------------
carg1's Profile: http://www.excelforum.com/member.php...o&userid=15271
View this thread: http://www.excelforum.com/showthread...hreadid=539430

 
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
Frustrating Boolean/loop iteration problem carg1[_15_] Excel Programming 2 May 5th 06 11:10 PM
Advancing to the next iteration of a loop? Maury Markowitz Excel Programming 4 April 2nd 05 05:39 PM
Boolean to advance loop ExcelMonkey[_190_] Excel Programming 1 March 14th 05 06:41 PM
Iteration loop Brad[_20_] Excel Programming 2 May 28th 04 03:11 PM
Iteration loop Brad[_20_] Excel Programming 0 May 28th 04 01:31 PM


All times are GMT +1. The time now is 09:45 PM.

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"