+ Reply to Thread
Results 1 to 4 of 4

How to trap an error

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    How to trap an error

    I have used the following code snippet to select the right sheet for printing.
    Please Login or Register  to view this content.
    I had not realised that there were situations where the user could get to this bit of code where UserForm1.LBYear (a ListBox) did not yet have a value.
    An easy way round this would be for me to put a value for yr in a cell,(Sheets("Utilities").Range("F17"), and in the error situation, which occurs when LBYear has no value, use this instead.
    I have not been able to satisfactorily code this and would like some help please.
    John

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: How to trap an error

    Just test for it.

    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to trap an error

    Another approach would be to ask the user for the "year" if variable "yr" is a Null String
    This could be done via InputBox with default value current year ?)
    Goes immediately below
    Please Login or Register  to view this content.
    Try something like this
    Please Login or Register  to view this content.
    Amend to 19 if VBA is expecting 2 digit year
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  4. #4
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: How to trap an error

    Thank you both for your help. All is well now. I should have been able to sort it by myself though!
    John

+ 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. [SOLVED] How to trap an error
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-13-2014, 10:07 AM
  2. How to error trap a vlookup that returns an error or #N/A
    By kjy1989 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-06-2013, 12:01 PM
  3. Complile Error: Type Mismatch ??? After adding error trap
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-22-2012, 03:50 PM
  4. Error Trap
    By Farnell in forum Excel General
    Replies: 2
    Last Post: 05-02-2007, 07:30 AM
  5. [SOLVED] Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 PM
  6. [SOLVED] Error Trap
    By Kirk P. in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2005, 04:51 PM
  7. Error Trap
    By TEB2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2005, 02:06 PM
  8. [SOLVED] On Error doesn't trap Application.Run error
    By blackhawk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-04-2005, 12:06 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