+ Reply to Thread
Results 1 to 6 of 6

How to move to next sheet if Name is not present within sheet name

  1. #1
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    How to move to next sheet if Name is not present within sheet name

    Hi All,

    I am looking for some help on this issue?
    I a spreadsheet "DBMileage" I have mileage by drivers, I want to add the mileage by each day for one week to a "Master" file. Each sheet name on the master file has the drivers name and is the same as the drivers name on the "DBMileage" sheet.
    So, at present the code I have will add mileage to each sheet, but only if the drivers name is present, if the code finds a drivers name that is not on the spreadsheet, I receive a subscript error that the drivers name is not on the master.
    How do I add this part into the code to say if the drivers name is not on the spreadsheet tab, move onto the to next sheet?
    Thanks

    Please Login or Register  to view this content.
    ==========
    Bigroo1958
    Austin, Texas
    ==========

  2. #2
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Re: How to move to next sheet if Name is not present within sheet name

    I have attached the two demo files pretty much stripped down to only the relevant data needed.
    Thanks
    Attached Files Attached Files

  3. #3
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: How to move to next sheet if Name is not present within sheet name

    You can intercept the "Subscript out of range" error with On Error Resume Next and evaluating Err.Number.
    If that's not zero then something isn't OK. Or if Err.Number is 9 then it's the "Subscript out of range" error.
    In that case you make the code jump to the next name/sheet.
    Make sure Error Trapping is set to "Break on unhandled errors". See Tools -> Options -> General
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,072

    Re: How to move to next sheet if Name is not present within sheet name

    How about
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013 & 2016
    Posts
    409

    Re: How to move to next sheet if Name is not present within sheet name

    Thanks to you both for the prompt reply!!
    Tsjallie, I am learning VBA and this has helped me a lot, I will remember this!

    Fluff13, your code modifications has done the trick and works as requested.
    Thanks to you both!

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,072

    Re: How to move to next sheet if Name is not present within sheet name

    Glad we could help & thanks for the feedback

+ 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. Replies: 6
    Last Post: 02-06-2018, 02:36 AM
  2. [SOLVED] Vba code to color text in sheet 1 based on key words present in next sheet.
    By sapnawat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2018, 04:26 AM
  3. how to populate unique count in sheet 1 when the data is present in sheet 2.
    By Vishnu Balan in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-28-2014, 11:20 PM
  4. [SOLVED] Copy row from sheet 1 to next row in sheet 2. delete from sheet 1 and move rows up
    By papabob1954 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-16-2012, 09:38 PM
  5. Replies: 2
    Last Post: 09-06-2011, 09:22 AM
  6. Copy Sheet & Create New Monthly Sheet From Present Sheet
    By unley in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2010, 12:00 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