Find and replace from many columns

Ottma

New Member
Joined
Apr 10, 2018
Messages
3
Hello
In sheet1 i have many columns with numbers like this

Code:
ColA ColB ColC
123   321  123
111   123  555
444   333  222

In sheet2 i have one column with numbers like this
Code:
ColA 
123
222
444
222

I want to search sheet1 for all numbers in sheet2 and remove them from sheet1,
Is that possible, without doing one column at a time?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Please try it with sample data.

Code:
Sub test()
Dim c
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
With ws1
    For Each c In .Range("A2").CurrentRegion
        If WorksheetFunction.CountIf(ws2.Range("A:A"), c) > 0 Then
            c.ClearContents
        End If
    Next
End With
End Sub
 
Upvote 0
That worked, Thank you
would it possible to get to work if sheet1 looked like this, but it only looked for the numbers in column A to C

ColA ColB ColC ColD
123 123 5467
456 121 1211
321 454 ASC
 
Upvote 0
Sorry, this is what i meant
Code:
[COLOR=#333333][I]ColA ColB ColC ColD[/I][/COLOR]
[COLOR=#333333][I]123 123          5467[/I][/COLOR]
[COLOR=#333333][I]456        121 1211[/I][/COLOR]
[COLOR=#333333][I]        321 454 ASC
[/I][/COLOR]
 
Upvote 0
If you numbers are values, rather than the result of formulae, try
Code:
Sub removevalues()

   Dim Ary As Variant
   Dim i As Long
   
   Ary = Sheets("Sheet2").Range("A2", Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp))
   For i = LBound(Ary) To UBound(Ary)
      Sheets("Sheet1").Range("A:C").Replace Ary(i), "", xlWhole, , False, , False, False
   Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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