This code is an attempt to delete columns that contain Header rows that match the “Text” in the Array (list).
The code successfully deletes the column based on the 1st array value "Header Text 1".
The problem occurs during the 2nd pass of the loop on A.EntireColumn.Delete. When I print the vItem, it displays the expected “Header Text 2” value, which is the correct item in the array.
VBA Error – Runtime error ‘91’
Object variable or With block variable not set
Sub ArrayLoop()
Dim ColumnsToRemove As Variant
Dim vItem As Variant
Dim A As Range
ColumnsToRemove = Array("Header Text 1", "Header Text 2", "Header Text 3")
For Each vItem In ColumnsToRemove
Set A = Rows(1).Find(What:=(ColumnsToRemove), LookIn:=xlValues, lookat:=xlPart)
Debug.Print vItem
A.EntireColumn.Delete
Next
End Sub