HalfAce
MrExcel MVP
- Joined
- Apr 6, 2003
- Messages
- 9,456
OK, let me see if I can describe my problem.
I'm trying to copy from sheet 1 to sheet 2.
In Col.B I have dates (from B2 to B613)
In Col.C I have times (same rows)
What I'm trying to do is loop through the range (B13:B613) and if the date is = to the date above it, or to the last date in sheet 2, copy the date to sheet 2.
This doesn't seem like it should be hard but I can't seem to get it right.
I've tried (among others) the routine below.
It copies only the last matching date to sheet 2. (Ignores any matches before the last one, and it doesn't copy the consecutively matching dates...only one instance of it.
I can't see why it shouldn't work. Can anyone else see what I'm missing?
Thanks,
Dan
I'm trying to copy from sheet 1 to sheet 2.
In Col.B I have dates (from B2 to B613)
In Col.C I have times (same rows)
What I'm trying to do is loop through the range (B13:B613) and if the date is = to the date above it, or to the last date in sheet 2, copy the date to sheet 2.
This doesn't seem like it should be hard but I can't seem to get it right.
I've tried (among others) the routine below.
Code:
Sub CopyMatches()
Dim a, a1 As Range
Set a = Sheets("Sheet2").Range("B65536").End(xlUp)
Set a1 = a.Offset(1)
For i = 613 To 2 Step -1
If Cells(i, 2) = Cells(i, 2).Offset(-1) Or Cells(i, 2) = a Then
Cells(i, 2).Copy a1
End If
Next i
End Sub
It copies only the last matching date to sheet 2. (Ignores any matches before the last one, and it doesn't copy the consecutively matching dates...only one instance of it.
I can't see why it shouldn't work. Can anyone else see what I'm missing?
Thanks,
Dan