+ Reply to Thread
Results 1 to 5 of 5

Avoiding invalid worksheet references

  1. #1
    Registered User
    Join Date
    08-17-2012
    Location
    Pleasanton, CA
    MS-Off Ver
    Excel 2010
    Posts
    25

    Avoiding invalid worksheet references

    I am combining the information from multiple files--one per state, for several states--into a single large table so it's more easily reviewed. Each file has multiple worksheets, named for categories. The category/worksheet names are standardized, but not all worksheets are found in every file.

    There is some overlap of items from state to state, so my macro copies key fields from each worksheet and pastes them into the new table and adds a column on the left with the name of the category/worksheet each item came from. It then removes any duplicates to create a list of unique items. Across to the right, the table has two columns for each state, one to show if the item exists there, and the other the date it was added.

    In the final step I am using lookup formulas to populate the states columns, using the category/worksheet name from the left-hand column to identify which worksheet to pull from. When a worksheet doesn't exist in a source file, however, this creates an invalid reference.

    Is there any way to use VBA to identify which worksheets are in a file so I can use the results in an IF/THEN statement to bypass any lines that would create the invalid references? Or does someone have a more creative way to address this issue?

    Thank you!
    David

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Avoiding invalid worksheet references

    Post the relevant portion of the code you're using now.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    08-17-2012
    Location
    Pleasanton, CA
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Avoiding invalid worksheet references

    The portion that will currentlyl generate an error is:

    Please Login or Register  to view this content.
    This is essentially the code that will be run for each state, and it generates an error when the value in column B generates a sheet name for "strSheetNm" that doesn't exist in the current source file being accessed.

    I am also looking into if I can use "On Error to skip the formulas, increment the counter and move to the next line in the destination table.

    Thank you!
    Last edited by dleslieca; 02-25-2014 at 06:32 PM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Avoiding invalid worksheet references

    Maybe


    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-17-2012
    Location
    Pleasanton, CA
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Avoiding invalid worksheet references

    Thanks, shg. That's pretty close to what I did, which was add "On Error Resume Next" prior to each formula, so it skips the errors and goes to the next line. That works, but I'd still like to know if there's some way to look at which worksheets exist in a file before executing the next line. I'll mark this as solved.

+ 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] get rid of "A formula in this worksheet contains one or more invalid references"
    By Thecyclist in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-14-2013, 11:26 AM
  2. "A formula in this worksheet contains one or more invalid references"
    By Canuckle777 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-18-2013, 12:19 PM
  3. a formula in this worksheet contains one or more invalid references
    By braydon16 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-17-2013, 02:44 PM
  4. Invalid References
    By dblcrona in forum Excel General
    Replies: 2
    Last Post: 02-21-2011, 12:59 PM
  5. Invalid references
    By plain in forum Excel General
    Replies: 2
    Last Post: 10-22-2006, 02:14 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