Strongpauly
Computer
- Mar 19, 2004
- 3
I'm trying to write a macro that will delete a column in excel if the title has a certain sequence of letters. I can't seem to get the syntax right, or maybe im going about it in completely the wrong way as im an absolute novice when it comes to writing in VBA. So far i've got:
Sub Test_Deleting()
Dim Looking As Long
Dim TotalColumns As Long
Looking = 0
TotalColumns = Application.WorksheetFunction.CountA(Range("1:1"))
Do While Looking <> TotalColumns
Looking = Looking + 1
If Application.WorksheetFunction.IsError(Application.WorksheetFunction.Search("exp", Cells(1, Looking))) = False Then Selection.EntireColumn.Delete
Loop
End Sub
I wasn't sure if there was a VBA function to search the active cell for a certain string, so i tried to use the excel functions. I can get Excel to distinguish between those columns with the string in the title, and those without, but can't seem to get it to work in VBA.
Any help would be appreciated
Thanks SP
Sub Test_Deleting()
Dim Looking As Long
Dim TotalColumns As Long
Looking = 0
TotalColumns = Application.WorksheetFunction.CountA(Range("1:1"))
Do While Looking <> TotalColumns
Looking = Looking + 1
If Application.WorksheetFunction.IsError(Application.WorksheetFunction.Search("exp", Cells(1, Looking))) = False Then Selection.EntireColumn.Delete
Loop
End Sub
I wasn't sure if there was a VBA function to search the active cell for a certain string, so i tried to use the excel functions. I can get Excel to distinguish between those columns with the string in the title, and those without, but can't seem to get it to work in VBA.
Any help would be appreciated
Thanks SP