Senin, 27 April 2015

Create Excel VBA Macro to Delete Duplicate Cells in One Row

Ok guys, we want to make this:

to be like this:

Well, here is the code:

Public Function LastRow() As Long
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, ActiveCell.Column).End(xlUp).Row
    End With
End Function

Sub deldup()
For n = ActiveCell.Row To LastRow()
    Do While (Cells(n, ActiveCell.Column).Value = Cells(n - 1, ActiveCell.Column).Value) And (Cells(n, ActiveCell.Column).Value <> "")
Next n
End Sub

to use this macro, just select the top of the row that we want to delete the duplicate cell, in this case is B3.
then just run the macro....done.


Tidak ada komentar:

Posting Komentar