You very kindly gave me this code for deleting columns with certain stated values - "Value A", "Value B" etc - in row 3:
Sub deleteCols()
Dim delArray As Variant, delRange As Range, addr As String
Dim str As Variant, found As Range, delCols As Range
delArray = Array("Value A", "Value B")
Set delRange = Rows(3)
For Each str In delArray
Set found = delRange.Find(what:=str)
If Not found Is Nothing Then
addr = found.Address
Do
If delCols Is Nothing Then
Set delCols = found
Else
Set delCols = Union(delCols, found)
End If
Set found = delRange.FindNext(found)
Loop While addr <> found.Address
End If
Next str
If Not delCols Is Nothing Then delCols.EntireColumn.Delete
End Sub
Is there a way of amending this to delete all columns with entries in column 3 EXCEPT those with certain values - "Value A", "Value B" etc?
.
Sub deleteCols()
Dim delArray As Variant, delRange As Range, addr As String
Dim str As Variant, found As Range, delCols As Range
delArray = Array("Value A", "Value B")
Set delRange = Rows(3)
For Each str In delArray
Set found = delRange.Find(what:=str)
If Not found Is Nothing Then
addr = found.Address
Do
If delCols Is Nothing Then
Set delCols = found
Else
Set delCols = Union(delCols, found)
End If
Set found = delRange.FindNext(found)
Loop While addr <> found.Address
End If
Next str
If Not delCols Is Nothing Then delCols.EntireColumn.Delete
End Sub
Is there a way of amending this to delete all columns with entries in column 3 EXCEPT those with certain values - "Value A", "Value B" etc?
.