Prova questo differente appriccio dove viene eseguita la ricerca di una stringa di testo (in questo caso la ricerca è sull'intero contenuto e non su una parte con l'opzione LookAt:=xlWhole) nel foglio di lavoro e nel caso venga trovato viene eliminata la
colonna:
Sub EliminaColonnePerValore()
Const sValore As String = "USD"
Dim Risposta As Long
Dim FindValue As Range
Dim bFindIsNothing As Boolean
Risposta = MsgBox("Verranno eliminate tutte le colonne che contengono " & _
"una cella con il valore " & sValore & "!" & vbNewLine & _
"Continuare?", vbYesNo + vbDefaultButton2 + vbExclamation, "Elimina Colonne")
If Risposta = vbNo Then Exit Sub
On Error GoTo Errore
With Application
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
With ActiveSheet
Do
Set FindValue = .Cells.Find(What:=sValore, _
After:=.Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
bFindIsNothing = FindValue Is Nothing
If Not bFindIsNothing Then FindValue.EntireColumn.Delete
Loop Until bFindIsNothing
End With
RiprendiErrore:
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.ScreenUpdating = True
End With
Exit Sub
Errore:
MsgBox "Si è verificato un errore!" & vbNewLine & _
"Errore n. " & Err.Number & vbNewLine & _
Err.Description, vbCritical, "Errore VBA"
End Sub