Hey everyone this is my first post on any excel forums. I can usually find a solution just by browsing but not this time. What i'm trying to do sounds simple enough. I have 2 Columns of data, example;
1-Apr 1423
1-Apr 1426
24-Apr 1430
8-May 1454
8-May 1460
15-May 1500
15-Jun 1525
15-Jun 1555
15-Jun 1556
I want to clear (not delete) the cells with a duplicate date in them while keeping the cell with the number next to it. So in this case they would be A2, A5, A8, A9. I've come up with a code that looks pretty logical but it doesn't work. Here's what it looks like.
Nothing much happens when i run this, it goes to the empty cell under the last used cell and doesn't clear anything.Code:Public Sub ClearDupes() Dim iRows As Integer Dim i As Integer Dim lCount As Integer lCount = 1 iRows = ActiveSheet.UsedRange.Rows.Count iRows = iRows - 1 Sheets("Temp").Range("A1").Activate Do Until IsEmpty(ActiveCell) For i = 1 To iRows If ActiveCell Is ActiveCell.Offset(i, 0) Then ActiveCell.Offset(i, 0).Clear lCount = lCount + 1 Else: End If Next i ActiveCell.Offset(lCount, 0).Select lCount = 1 Loop End Sub
TIA
-Chris
--Edited a few bits of the code.
Last edited by Falantar; 05-07-2009 at 01:02 PM. Reason: Solved
Welcome to the forum.
Try this:
Code:Public Sub ClearDupes() Dim iRow As Long With Worksheets("Temp") For iRow = .Cells(.Rows.Count, "A").End(xlUp).Row To 2 Step -1 With .Cells(iRow, "A") If .Value = .Offset(-1).Value Then .ClearContents End With Next iRow End With End Sub
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Wow, worked like a charm. Thanks for the quick reply!
SHG's solution is great as usual. It would need a slight tweak if your goal was to stop at the first blank cell.
Here is my approach from the bottom down to first blank cell. Of course it would need a slight tweak if your goal was to process all the cells in column A (bottom up approach).
Code:Sub ClearDupsInA() Dim c As Range, val As Long With Sheets("Temp") val = .Range("A1").Value For Each c In .Range("A2", .Range("A2").End(xlDown)) If Not (IsEmpty(c.Offset(-1, 0))) Then val = c.Offset(-1, 0).Value If c.Value = val Then c.ClearContents Else: val = c.Value End If Next c End With End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks