98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » excel computer course london - On error statements
excel computer course london - On error statements
Resolved · Low Priority · Version Standard
Samantha has attended:
Excel VBA Intro Intermediate course
On error statements
I have a For Next loop where i am searching for a variable within the loop.
I have an ON ERROR statement before the loop to say goto a stamp which says "Next" so that if the program cant find the variable, it will just do the next one.
The loop occurs three times, first with no error, second with an error and then third with an error again. And on the third error i get an "Error 91 Object variable..." error message.
I dont understand why when it gets to the second time the error occurs, it will not go to the error stamp to go Next again.
Code below:
On Error GoTo nextagent
For a = 6 To grandtotal1 - 1
'start with first agent and assign agent name
Range("A" & a).Select
agentname = ActiveCell.Value
Range("G5:J" & grandtotal2 - 1).Select
Selection.Find(What:=agentname, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
'set a variable which sets the agent found row
agentfound = ActiveCell.Row
'log the low month position
Range("E" & a).Select
'now get low position by taking the activerow and minusing 5 rows (top header rows)
positionlow = agentfound - 5
ActiveCell.Value = positionlow
'now put the increase/decrease % into column F
Range("F" & a).Select
ActiveCell.FormulaR1C1 = "=SUM(R[" & agentfound - a & "]C[4]/RC[-2])-1"
Selection.NumberFormat = "0.00%"
nextagent:
Next
Can anyone help?
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Display Functions on WorksheetsFunctions in Excel can be difficult to recall their format/syntax |