+ Reply to Thread
Results 1 to 4 of 4

Error handling loop vba

  1. #1
    Registered User
    Join Date
    02-11-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    27

    Error handling loop vba

    Hi all

    I have a for loop as follows:

    'initiate inner loop
    For j = 1 To LastRowCashAcc

    'Buy side checks (includes generic such as Tcodes and base currency)
    If BUYcashStr = wbDeb.Worksheets("All Cash Accounts").Cells(j, 2) Then
    'Check buy cash account currencies
    BUYacc_ccy = wbDeb.Worksheets("All Cash Accounts").Cells(j, 4)
    End If
    Next j

    When BUYcashStr does not appear in the wbDeb worksheet I obviously get an error. I need to handle this to skip to the next iteration i.e. Next j?

    Many thanks

    Jack

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Error handling loop vba

    Jack

    Do you definitely get an error?

    I ask becaus I can't quite see how no finding match for a value would cause an error.

    By the way, your code is already set up to skip to the next iteration of the loop if BUYcashStr isn't found in the current row on 'All Cash Accounts.

    PS Ever considered using VLOOKUP?
    If posting code please use code tags, see here.

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Error handling loop vba

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  4. #4
    Registered User
    Join Date
    02-11-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Error handling loop vba

    Hi I have truncated the loop apologies - I think the error actually comes further down when trying to calculate pcTrans (type mismatch error)

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. For Loop and Error Handling
    By peetman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2015, 08:00 AM
  2. [SOLVED] Error Handling in a loop
    By Turtleman10 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-29-2013, 10:27 AM
  3. Error Handling in a Loop
    By amdk8800 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-28-2013, 03:46 PM
  4. Error handling within a Do Loop
    By Boondoggler in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-01-2012, 12:15 AM
  5. Error handling within loop
    By DesignMind in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-22-2009, 01:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1