equal one of the values in Col. F
I suppose you mean any of the cells in col F not necessarily in the same row
as you are messing with with data copy data (in sheet1) to sheet2 also to preserve the data
the data in sheet 1 (and also in sheet 2) will be first like this
hdng1 hdng2 hdng3 hdng4 hdng5 hdng6
1 2 3 x x 2
4 10 6 x x 3
7 8 9 x x 4
3 5 7 x x 5
2 7 9 x x 6
try the macro "test". macro "undo_macro" is to get back original data in sheet1
Sub test()
Dim r As Range, c As Range, cfind As Range, x
Set r = Range(Range("B2"), Range("B2").End(xlDown))
For Each c In r
x = c
With Columns("F:F")
Set cfind = .Cells.Find(what:=x, lookat:=xlWhole)
If Not cfind Is Nothing Then
Range(c.Offset(0, -1), c.Offset(0, 1)).Cells.Clear
Else
GoTo nextc
End If
End With
nextc:
Next c
End Sub
Sub undo_macro()
Worksheets("sheet1").Cells.Clear
Worksheets("sheet2").Cells.Copy
Worksheets("sheet1").Range("A1").PasteSpecial
End Sub
Bookmarks