-=Scan and replace=-

TAPAKAH

New Member
Joined
Apr 16, 2004
Messages
9
Hi guys,

Trying to do the basic search and destroy, but with a little modification.
I have one column where values repeat:

Example:

1
2
4
5
1

So a macro would start at the top, look at first row, and then go down the column and look if there is same value somewhere down the column and if found replace it with a 0. Then it would come back go to the second row and do the same untill the end.

I would really appreciate any help.

Thanks in advance.

:)
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Something like this?

Code:
Sub SearchandDestroy()
Const strColumn As String = "A"
Dim cell As Range, cell2 As Range, lngLastRow As Long

    Application.ScreenUpdating = False
    lngLastRow = Range(strColumn & 65536).End(xlUp).Row
    For Each cell In Range(strColumn & 1 & ":" & strColumn & lngLastRow - 1)
        For Each cell2 In Range(cell.Offset(1, 0).Address & ":" & strColumn & lngLastRow)
            If cell = cell2 Then cell2 = 0
        Next
    Next
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
Another possible solution.... :cool:

Suppose you have data in column A staring from A2 (column header in A1).
The following code should suit your request.

It copies a unique copy of data soon after the last row of data and delete above data.

Sub ScanAndReplace()
Dim MyRange As Range
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
If Range("A2") <> "" And Range("A3") <> "" Then
Set MyRange = Range(Range("A2"), Range("A2").End(xlDown))
Range(Range("A1"), Range("A2").End(xlDown)).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
MyRange.SpecialCells(xlCellTypeVisible).Copy Destination:=Cells(MyRange.Rows.Count + 2, 1)
ActiveSheet.ShowAllData
MyRange.Rows.Delete shift:=xlUp
End If
End Sub
 
Upvote 0
is it possible to tell the macro to not match the case(lower or upper) of the text i believe it is "MatchCase:=False".... but i am not sure where to put it.
 
Upvote 0
Replace statement

If cell = cell2 Then cell2 = 0

with

If LCase(cell) = LCase(cell2) Then cell2 = 0

Ciao
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,192
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top