I have two worksheets in Excel. One, ("List") has a list of 2000 or so rows. The other ("Library") has a large array of 2000 or so columns, each with 150 rows. I want to delete each column in "Library" that has nothing in it appear in "List".
What I have so far (using the CountIf function) is:
Sub DeleteLibrary()
Dim Rng As Range
Dim Keyword As Range
Dim Library As Worksheet
Dim List As Worksheet
Dim Chunk As Range
Dim X As Long
X = 1
Application.ScreenUpdating = True
Set Library = Sheets("Library")
Set List = Sheets("List")
Set Keyword = List.Range("A1:A2000")
Set Chunk = Library.Range("A1:A150").Offset(0, X)
Do While X <= 1500
If Application.WorksheetFunction.CountIf(Keyword, Chunk) >= 1 Then
X = X + 1
ElseIf Application.WorksheetFunction.CountIf(Keyword, Chunk) = 0 Then
Chunk.Delete Shift:=xlLeft
Else: Stop
End If
Loop
End
End Sub
However, this gives me a type mismatch for the first CountIf line. Am I taking the right approach? Would Union or Intersect be a better route?
Thanks