error handling within loop
Microsoft Office Training verified by visa - mastercard securecode about microsoft training company london ukadd this page to your favourites/bookmarksAdd to favourites
view a printable version of this pagePrintable version
email this page to somebodyEmail this page
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and Help » Error handling within loop

Error handling within loop

The UK's most regular instructor-led training courses.
Training information: vba excel course london · Excel training london · VBA training in London

resolvedResolved · Low Priority · Version Standard

Error handling within loop

Samantha has attended:
Excel VBA course

by - delegate Samantha [21 posts] (2008 Mar 13 Thu, 12:38) replyReply

i am getting in a pickle with error handling and am getting debug when running these within a loop. please can you help?

my coding is:

On Error GoTo theend

Range("A1").Select
'find the word "Continued"
Cells.Find(What:="Continued", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate

'this will activate a procedure to format the "continued" data
GoTo Openitagain

theend:

so i keep going until the system can no longer find "Continued" and i expect that when it cant, it will go to "theend". but instead it debugs.
i presume this is because i keep opening the on error goto the end and not closing it down?

but where can i close it down and what code do i use? i tried within the "openitagain" area and put a resume or resume next but this just goes to the "theend" which isnt helpful

can you please help?

thanks
sam

Excel Intermediate 1 day course
Version Date Location Places
available
Book Next place rate:
Card Invoice
2007 2008 Jul 8 Tue Bloomsbury 0 FULL    
2003/XP 2008 Jul 8 Tue Bayswater 1 book now £195 £205
2003/XP 2008 Jul 9 Wed Bloomsbury 3 book now £210 £215
2003/XP 2008 Jul 15 Tue Bloomsbury 3 book now £210 £215
2003/XP 2008 Jul 15 Tue Tooting 0 FULL    
2007 2008 Jul 16 Wed Bloomsbury 7 book now £202 £224
Full Schedule: See all 160 Excel Intermediate course dates.
Bookings currently available until 25th November 2009.

RE: error handling within loop

by - trainer Roy [16 posts] (2008 Mar 28 Fri, 15:25) replyReply

Hi Samantha,

You shouldn't be using error handling in this case, as the situation is entirely under program control. Error handling is for things that are outside your control like trying to open a workbook that's been renamed, moved or deleted.

The Range.Find method returns the special value 'Nothing' if it can't find the What argument. You can check for this in your loop condition or with an If statement. See the online Help page for Range.Find (and the Example code).

Also:
-- If you're looking for a literal value, then LookIn should :=xlValues.
-- You shouldn't need to use a GoTo -- this generally bad coding practice. Just call the necessary procedure, which can operate on ActiveCell.

Hope this helps
/Roy


Related articles

· Customized Financial Excel Courses in London
· Excel Advanced Courses Ease the Frustration of Learning Complex Tasks
· Compare Different MS Excel Training Methods
· How to Create Better Excel Spreadsheets: Part Four
· Do You Really Need Excel VBA Training?

Please browse our web site to find out more about
vba excel course london and other Microsoft training courses.

Excel tip:

Use the Format Painter to copy formatting more than once in Excel

The format painter tool provides a quick and easy way to copy formatting from one cell to another in Word.

The only problem is that if you click the Format Painter once to turn it on, you can only click and drag over a single cell or adjacent range of cells; then the Format Painter turns itself off automatically.

If you want to copy formatting to cells or groups of cells that are not adjacent to each other, double-click the Format Painter - this way you will be able to copy formatting to multiple cells.

When you have finished using Format Painter, press the Esc key or click on the Format Painter button once to turn it off.

View all Excel hints and tips

Institute of IT Training - Accredited Training Provider Institute of IT Training - Accredited Training Provider Prodigy Platinum Learning Partner Microsoft Office Specialist Authorised Testing Centre

Microsoft Registered Partner
microsoft office
ms office project server

Association of Computer Trainers Valid HTML 4.01 Transitional
Valid CSS Markup

secure online payments - visa - mastercard

Mini sitemap. These are the main areas of our web site. Full sitemap.

Training by application Main information pages See also

Access courses
DreamWeaver courses
Excel courses
MS Project courses
Outlook courses
PowerPoint courses
VBA courses
Word courses
(more...)

Public scheduled courses
On-site training
Closed company courses

Microsoft Office training
Pricing and availability
Training schedule
Training venues

Access training
Dreamweaver training
Excel training
MS Project training
PowerPoint training

London Computer Training
Computer Training London

Microsoft Access training
Microsoft Excel training
Microsoft Project training
Microsoft Outlook training
Microsoft Powerpoint training
Microsoft Word training

Time Management Course London

Interested in Access training? Please see the following pages:
microsoft access courses · microsoft training access course
microsoft+access+training · access courses in london

Training Information
AddThis Social Bookmark Button What's this?
Add to Del.icio.us Add to Facebook Add to Digg Add to Reddit Add to Google Add to Yahoo Add to Diigo Add to Mr. Wong Add to Linkarena Add to Power Oldie Add to Folkd Add to Jumptags Add to Upchuckr Add to Simpy Add to StumbleUpon Add to Slashdot Add to Netscape Add to Furl Add to Spurl Add to Blinklist Add to Blogmarks Add to Technorati Add to Newsvine Add to Blinkbits Add to Ma.Gnolia Add to Smarking Add to Netvouz