Error 91

%3CLINGO-SUB%20id%3D%22lingo-sub-1136083%22%20slang%3D%22en-US%22%3EError%2091%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1136083%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EI%20am%20having%20an%20%22Error%2091%22%20issue.%20My%20code%20includes%20%22Error%20Handling%22%2C%20but%20for%20some%20reason%2C%20after%20the%20cell%20search%20has%20failed%20once%20and%20correctly%20executed%20my%20code%2C%20a%20subsequent%20search%20failure%20causes%20the%20macro%20to%20bomb%20with%20%22Error%2091%22.%20It's%20as%20though%20a%20line%20of%20reset%20code%20is%20needed%20after%20the%201st%20failed%20search.%20I%2Cm%20hoping%20someone%20is%20able%20to%20figure%20out%20what%20I%2Cm%20doing%20wrong.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EHere%20is%20my%20complete%20code...%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3ESub%20Confirm_Quicken_Data_Links()%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3E'%20This%20macro%20searches%20the%20%22Expenditure%22%20sheet%20for%20each%20Payee%20Link%20held%20in%20%22Quicken%20Data%22.%20Search%20results%20are%20stored%20in%20the%20%22LinkTest%22.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E'%20A%20check%20is%20made%20for%20Payees%20having%20a%20%222-Line%22%20Header%20text.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EDim%20N%20As%20Integer%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EDim%20X%20As%20String%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EDim%20Y%20As%20Integer%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EDim%20Row%20As%20Integer%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EDim%20Col%20As%20Integer%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EDim%20Payee%20As%20String%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EDim%20PayeeAddrs%20As%20String%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EDim%20PayeeLinkAddrs%20As%20String%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EDim%20Payees%20As%20Integer%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EDim%20ExpenseCategory%20As%20String%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EDim%20LinkRange%20As%20Range%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3ESheets(%22Quicken%20Data%22).Select%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EN%20%3D%200%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERange(%22B1%22).Select%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ESelection.End(xlToRight).Select%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EPayees%20%3D%20ActiveCell.Column%20-%201%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ESet%20LinkRange%20%3D%20Sheets(%22Expenditures%22).Range(%22LinkRange%22)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERange(%22B1%22).Offset(0%2C%20N).Select%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EDo%20While%20N%20%26lt%3B%3D%20Payees%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EErr.Clear%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EPayee%20%3D%20ActiveCell%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EPayeeAddrs%20%3D%20ActiveCell.Address%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EPayeeLinkAddrs%20%3D%20ActiveCell.Offset(15%2C%200).AddressLocal%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EPayeeAddrs%20%3D%20%22'Quicken%20Data'!%22%20%26amp%3B%20PayeeAddrs%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EX%20%3D%20%22IFERROR(SEARCH(CHAR(10)%2C%22%20%26amp%3B%20PayeeAddrs%20%26amp%3B%20%22)%2C0)%22%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERange(%22SearchCell_2%22).Select%20'%20Cell%20location%20for%20%22Formula%22%20search%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EActiveCell.Formula%20%3D%20%22%3D%22%20%26amp%3B%20X%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EIf%20ActiveCell.Value%20%3D%200%20Then%20'%201-LINE%20Header%20Text(Payee%20Name)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EY%20%3D%200%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EElse%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EY%20%3D%201%20'%202-LINE%20Header%20Text(Payee%20Name)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EEnd%20If%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ESheets(%22Expenditures%22).Select%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERange(%22A1%22).Select%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EOn%20Error%20Resume%20Next%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ECells.Find(What%3A%3DPayeeLinkAddrs%2C%20After%3A%3DActiveCell%2C%20LookIn%3A%3DxlFormulas%20_%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%2C%20LookAt%3A%3DxlPart%2C%20SearchOrder%3A%3DxlByRows%2C%20SearchDirection%3A%3DxlNext%2C%20_%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EMatchCase%3A%3DTrue%2C%20SearchFormat%3A%3DFalse).Activate%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EOn%20Error%20GoTo%20NOTFOUND%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EIf%20Err.Number%20%3D%200%20Then%20'%20No%20Error%20-%20Search%20String%20Found%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EExpense%20%3D%20ActiveCell.Offset(0%2C%20-5).Value%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ESheets(%22LinkTest%22).Select%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERange(%22A2%22).Offset(N%2C%200).Select%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EIf%20Y%20%3D%201%20Then%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EX%20%3D%20%22Replace(%22%20%26amp%3B%20PayeeAddrs%20%26amp%3B%20%22%2C%20Search(CHAR(10)%2C%22%20%26amp%3B%20PayeeAddrs%20%26amp%3B%20%22)%2C%201%2C%20CHAR(32))%22%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EActiveCell.Formula%20%3D%20%22%3D%22%20%26amp%3B%20X%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EElse%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EActiveCell%20%3D%20Payee%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EEnd%20If%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERange(%22A2%22).Offset(N%2C%201)%20%3D%20PayeeLinkAddrs%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERange(%22A2%22).Offset(N%2C%202)%20%3D%20Expense%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EElse%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3ENOTFOUND%3A%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ESheets(%22LinkTest%22).Select%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERange(%22A2%22).Offset(N%2C%200).Select%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EIf%20Y%20%3D%200%20Then%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EX%20%3D%20%22Replace(%22%20%26amp%3B%20PayeeAddrs%20%26amp%3B%20%22%2C%20Search(CHAR(10)%2C%22%20%26amp%3B%20PayeeAddrs%20%26amp%3B%20%22)%2C%201%2C%20CHAR(32))%22%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EActiveCell.Formula%20%3D%20%22%3D%22%20%26amp%3B%20X%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EElse%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EActiveCell%20%3D%20Payee%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EEnd%20If%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERange(%22A2%22).Offset(N%2C%201)%20%3D%20PayeeLinkAddrs%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERange(%22A2%22).Offset(N%2C%202)%20%3D%20%22Not%20Found%22%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EEnd%20If%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EN%20%3D%20N%20%2B%201%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EExpense%20%3D%20%22%22%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ESheets(%22Quicken%20Data%22).Select%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERange(PayeeLinkAddrs).Offset(-15%2C%201).Select%20'%20Next%20Payee%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ELoop%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EEnd%20Sub%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1136083%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

I am having an "Error 91" issue. My code includes "Error Handling", but for some reason, after the cell search has failed once and correctly executed my code, a subsequent search failure causes the macro to bomb with "Error 91". It's as though a line of reset code is needed after the 1st failed search. I,m hoping someone is able to figure out what I,m doing wrong.

 

Thanks.

Here is my complete code...

Sub Confirm_Quicken_Data_Links()

' This macro searches the "Expenditure" sheet for each Payee Link held in "Quicken Data". Search results are stored in the "LinkTest".
' A check is made for Payees having a "2-Line" Header text.

Dim N As Integer
Dim X As String
Dim Y As Integer
Dim Row As Integer
Dim Col As Integer
Dim Payee As String
Dim PayeeAddrs As String
Dim PayeeLinkAddrs As String
Dim Payees As Integer
Dim ExpenseCategory As String
Dim LinkRange As Range


Sheets("Quicken Data").Select
N = 0
Range("B1").Select
Selection.End(xlToRight).Select
Payees = ActiveCell.Column - 1
Set LinkRange = Sheets("Expenditures").Range("LinkRange")
Range("B1").Offset(0, N).Select
Do While N <= Payees
Err.Clear
Payee = ActiveCell
PayeeAddrs = ActiveCell.Address
PayeeLinkAddrs = ActiveCell.Offset(15, 0).AddressLocal
PayeeAddrs = "'Quicken Data'!" & PayeeAddrs
X = "IFERROR(SEARCH(CHAR(10)," & PayeeAddrs & "),0)"
Range("SearchCell_2").Select ' Cell location for "Formula" search
ActiveCell.Formula = "=" & X
If ActiveCell.Value = 0 Then ' 1-LINE Header Text(Payee Name)
Y = 0
Else
Y = 1 ' 2-LINE Header Text(Payee Name)
End If
Sheets("Expenditures").Select
Range("A1").Select
On Error Resume Next
Cells.Find(What:=PayeeLinkAddrs, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Activate
On Error GoTo NOTFOUND
If Err.Number = 0 Then ' No Error - Search String Found
Expense = ActiveCell.Offset(0, -5).Value
Sheets("LinkTest").Select
Range("A2").Offset(N, 0).Select
If Y = 1 Then
X = "Replace(" & PayeeAddrs & ", Search(CHAR(10)," & PayeeAddrs & "), 1, CHAR(32))"
ActiveCell.Formula = "=" & X
Else
ActiveCell = Payee
End If
Range("A2").Offset(N, 1) = PayeeLinkAddrs
Range("A2").Offset(N, 2) = Expense
Else

NOTFOUND:
Sheets("LinkTest").Select
Range("A2").Offset(N, 0).Select
If Y = 0 Then
X = "Replace(" & PayeeAddrs & ", Search(CHAR(10)," & PayeeAddrs & "), 1, CHAR(32))"
ActiveCell.Formula = "=" & X
Else
ActiveCell = Payee
End If
Range("A2").Offset(N, 1) = PayeeLinkAddrs
Range("A2").Offset(N, 2) = "Not Found"
End If
N = N + 1
Expense = ""
Sheets("Quicken Data").Select
Range(PayeeLinkAddrs).Offset(-15, 1).Select ' Next Payee
Loop
End Sub

0 Replies