Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Frustrating Boolean/loop iteration problem | Excel Programming | |||
Advancing to the next iteration of a loop? | Excel Programming | |||
Boolean to advance loop | Excel Programming | |||
Iteration loop | Excel Programming | |||
Iteration loop | Excel Programming |