I am trying to delete all columns except names currently the code below deletes names.
Private Sub CommandButton2_Click()
Dim i As Integer
Dim A As Range
For i = 100 To 1 Step -1
Set A = Cells(1, i).Find(What:="Names", LookIn:=xlValues)
If Not A Is Nothing Then A.EntireColumn.Delete
Next i
End Sub
Updated Code:
Private Sub CommandButton1_Click()
Dim i As Integer
Dim A As Range
If Cells(1, i) <> "Names" Then
If A Is Nothing Then A.EntireColumn.Delete
End If
End Sub