Cell searching and delete function

D

Dan C.

What I need to figure out how to do is search through a certain group of
cells like--C1:C250, and if it matches with G2, I would like whatever "C"
cell that matches with the "G" cell deleted. I hope this makes sense. I have
no idea how to make this happen or if it is possible

Searches C1:C250 and finds match for cell G2 then deletes the "C" cell.

Any help would be wonderful.
 
L

Luke M

You will need to use a macro. Open the VBE (Alt+F11), Insert - Module. Paste
this in:

Sub FindAndDestory()
For Each cell In Range("C1:C250")
If cell.Value = Range("G2") Then
cell.ClearContents
End If
Next cell
End Sub

'You can then play this macro from XL, Under Tools-Macros-Maco
'Note that when you run this, it will apply to the sheet currently visible.
 
D

Dan C.

How do I modify that to continue to do that down every G cell

Ex: G2 then G3 then G4 etc to like G121?

I did play around with it to try to do this on my own but I do know have the
knowledge yet or brain capacity to figure it out. :)
 
L

Luke M

Sub FindAndDestroy()

For Each cell In Range("C1:C250")

With Range("G2:G121")
Set c = .Find(cell.Value, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
cell.ClearContents
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With

Next cell
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top