your code did not worked fully. I've made some changes. Its little messy, but it works.
Thank you JOHN H. DAVIS and Sourabhg98 for your help.
Sub igormigor()
Dim ws As Worksheet, ws1 As Worksheet, i As Long, y As Long, z As Long, r As Range
Set ws = Sheets("Table")
Set ws1 = Sheets("Required Columns")
ws.Range("1:1").Interior.ColorIndex = 10
With ws
For i = 1 To ws1.Range("A" & Rows.Count).End(3).Row
Set r = .Rows(1).Find(ws1.Cells(i, 1), LookIn:=xlValues, lookat:=xlWhole)
If Not r Is Nothing Then r.Interior.ColorIndex = 6
Set r = Nothing
Next i
y = .UsedRange.Columns.Count
For z = y To 1
Select Case .Cells(1, z).Interior.ColorIndex
Case Is = 6
GoTo zz
Case Else
.Columns(z).Delete
End Select
zz:
Next z
End With
With ws
For i = 1 To 100
If Sheets("Table").Range("a" & i).Interior.ColorIndex = 10 Then
.Columns(z).Delete
End If
Next i
End With
x = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column
xxx:
For i = 1 To x
If ws.Cells(1, i).Interior.ColorIndex <> "6" Then
Columns(i).EntireColumn.Delete
i = i + 1
End If
Next i
test1 = WorksheetFunction.CountA(ws.Range("1:1"))
test2 = WorksheetFunction.CountA(ws1.Range("A:A"))
If test1 = test2 Then
Else
GoTo xxx
End If
ws.Range("1:1").Interior.ColorIndex = xlNone
End Sub
Bookmarks