As the title would suggest i want to remove any columns that do not match an array. I tried the following code but receive an error, does anybody have a possible solution?
I also tried using column numbers but I couldn't get it to work either!
Code:
Dim arr As Variant
arr = Array("Title", "Forename", "Surname", "Address 1", "Address 2", "Address 3", "Address 4", "Town", "County", "Postcode")
Set arrRange = RptSht.Range(RptSht.Cells(1, 1), RptSht.Cells(1, 10))
For Each cell In arrRange
If IsError(Application.Match(cell.Value, arr, 0)) Then
cell.EntireColumn.Delete
End If
Next
I also tried using column numbers but I couldn't get it to work either!
Code:
Dim ColNum As Long, arr As Variant
arr = Array(1, 2, 3, 4, 7, 8, 9, 10, 11, 12,13)
For ColNum = LstCol To 1 Step -1
If RptSht.Columns(ColNum) <> arr Then
RptSht.Columns(ColNum).Delete
End If
Next