Jomu

New Member
Joined
Apr 19, 2011
Messages
13
Anyone who could help me.
That macro asks if I want to delete or not. If I choose "not" it leaves current cell red. How can I degree that. If I choose not to delete it should
leave that cell as it was in the begin. Please help me.

Sub oma()
Range("A:A").Interior.ColorIndex = xlNone
For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
If WorksheetFunction.CountIf(Range("A1:A" & i), Cells(i, 1).Value) > 1 Then
Cells(i, 1).Interior.ColorIndex = 3
If MsgBox("Duplicates highted...Do you want to delete", vbYesNo) = vbYes Then
Cells(i, 1).EntireRow.Delete
End If
End If
Next i
End Sub
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,651
Sub oma()
Range("A:A").Interior.ColorIndex = xlNone
For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
If WorksheetFunction.CountIf(Range("A1:A" & i), Cells(i, 1).Value) > 1 Then
Cells(i, 1).Interior.ColorIndex = 3
If MsgBox("Duplicates highted...Do you want to delete", vbYesNo) = vbYes Then
Cells(i, 1).EntireRow.interior.colorindex=xlnone
Cells(i, 1).EntireRow.Delete
End If
End If
Next i
End Sub
 

Jomu

New Member
Joined
Apr 19, 2011
Messages
13
Hi. Thanks for the answer. However Your code still leaves cell red. That is just I do not want.
 

brettdj

Active Member
Joined
Feb 5, 2003
Messages
426
hth

Cheers

Dave

Code:
Sub oma()
    Range("A:A").Interior.ColorIndex = xlNone
    For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
        If WorksheetFunction.CountIf(Range("A1:A" & i), Cells(i, 1).Value) > 1 Then
            Cells(i, 1).Interior.ColorIndex = 3
            If MsgBox("Duplicates highted...Do you want to delete", vbYesNo) = vbYes Then
                Cells(i, 1).EntireRow.Delete
            Else
                 Cells(i, 1).Interior.ColorIndex = xlNone
            End If
        End If
    Next i
End Sub
 

Jomu

New Member
Joined
Apr 19, 2011
Messages
13
Thanks Breddtj

Thank You very much. This was just what I want to. However, is there any possibilty to add "cancel" to code, while searching duplicates from the sheet ?
Greetings from Finland.:LOL:
 

brettdj

Active Member
Joined
Feb 5, 2003
Messages
426
No probs

Sure, try this update

Code:
Sub oma()
Dim lngSel As Long
    Range("A:A").Interior.ColorIndex = xlNone
    For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
        If WorksheetFunction.CountIf(Range("A1:A" & i), Cells(i, 1).Value) > 1 Then
            Cells(i, 1).Interior.ColorIndex = 3
            lngSel = MsgBox("Duplicates highted...Do you want to delete", vbYesNoCancel)
            If lngSel = vbCancel Then Exit Sub
            If lngSel = vbYes Then
                Cells(i, 1).EntireRow.Delete
            Else
                 Cells(i, 1).Interior.ColorIndex = xlNone
            End If
        End If
    Next i
End Sub
 

Jomu

New Member
Joined
Apr 19, 2011
Messages
13
Thanks again. You are a MAN....

How about, is it possible that code goes throw not just A column but also B and C:s ? Kind regards






No probs

Sure, try this update

Code:
Sub oma()
Dim lngSel As Long
    Range("A:A").Interior.ColorIndex = xlNone
    For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
        If WorksheetFunction.CountIf(Range("A1:A" & i), Cells(i, 1).Value) > 1 Then
            Cells(i, 1).Interior.ColorIndex = 3
            lngSel = MsgBox("Duplicates highted...Do you want to delete", vbYesNoCancel)
            If lngSel = vbCancel Then Exit Sub
            If lngSel = vbYes Then
                Cells(i, 1).EntireRow.Delete
            Else
                 Cells(i, 1).Interior.ColorIndex = xlNone
            End If
        End If
    Next i
End Sub
 

Jomu

New Member
Joined
Apr 19, 2011
Messages
13
Hi. Is it possible that code shows which items are dublicates. I mean that I have made a button where macro exist and when i push that button macro starts. How ever it start from the bottom of the worksheet and goes upward. When the duplicate has been found it gives a message but doesnt show that row where dublicates are found. Buttons are at the top of the worksheet and those rows where buttons are are locked. I can send an example if it helps. :LOL:
 

Forum statistics

Threads
1,082,323
Messages
5,364,589
Members
400,808
Latest member
formulasataglance

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top