How to skip a step in an Excel Macro if data not found with Cell.Find
Posted on 2014-08-18
The following code snippet is from an Excel macro. It searches a column of data to find a particular string. Then performs a cut and paste of the data into another filed. There are three of these "sections" in my macro. One for "Admin Fee", one for "Distribution of Unassigned" and one for "Locality Transfer".
The issue is that sometimes these strings do not appear in the data. Presently the macro crashes when it doesn't find the string. I would like the macro to simply go to the next step if the string is not found.
I presume an IF - THEN statement is needed but I am not sure of the proper syntax. This is how I envision the error trap:
IF Cell. Find = True THEN
Next Step ELSE
GOTO NEXT SECTION
Am I on the right track? Any assistance will be appreciated.
'Move "Admin Fee" to name field and populate field cell with current tax period
Cells.Find(What:="Admin Fee", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
ActiveCell.Value = "1"
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlTop