excel computer course london - on error statements

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum 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

resolvedResolved · 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?

RE: On error statements

i have figured this out.
have put in an on error resume next at top
then set an if statement to say

if err.number <> 0 then
goto nextagent
end if

then at nextagent label included
err.clear

which then cleared the error.

 

Training courses

 

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Display Functions on Worksheets

Functions in Excel can be difficult to recall their format/syntax

For example, you want to use the =PMT function.

Enter =PMT, then select keystroke, CTRL+SHIFT+A.

This usful memory jog, will display the arguments of a function on a worksheet, allowing the user to proceed with the generation of the function



View all Excel hints and tips


Server loaded in 0.08 secs.