+ Reply to Thread
Results 1 to 8 of 8

Check if named range exists and ignore if it doesn't

  1. #1
    Registered User
    Join Date
    11-28-2007
    Posts
    6

    Check if named range exists and ignore if it doesn't

    Hello there

    I'm struggling to pull this one together.

    I'm trying to program a macro that checks to see if a named range exists and copy and paste the data if it does and ignore it if it doesn't or just ignore the error message would be good enough.


    Here's the code I'm using:

    Please Login or Register  to view this content.
    I keep getting a 1004 error whatever code I put in, any ideas?

    tia
    Last edited by lawtonl; 10-13-2009 at 10:33 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Check if named range exists and ignore if it doesn't

    This Function checks if a name exists
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

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

    Re: Check if named range exists and ignore if it doesn't

    I doubt this is correct, since I can't tell where the ranges are supposed to exist, but maybe you'll get the drift.

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    11-28-2007
    Posts
    6

    Re: Check if named range exists and ignore if it doesn't

    Thanks guys.

    Shg the ranges exist in each workbook a1 for title and b1 for accnum in the Suspects Import Template - test.xlsm workbook and it's a1:a20000 and b1:b20000 in the GB August.csv file. In both workbooks the named ranges are First and AccNum. Cause this will be an ongoing job I'll have to change the range in the csv file to copy from hence why I'm using ranges in the code rather than cell references.

    Using your code(cause I'm a VBA newbie) I get a 438 error on the following lines:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Check if named range exists and ignore if it doesn't

    Use the Function that I posted to check if the name exists
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-28-2007
    Posts
    6

    Re: Check if named range exists and ignore if it doesn't

    Royuk, thanks. I tried the code you suggested and using the following code I still get the same error, Error 1004 at the same place:


    Please Login or Register  to view this content.
    Could it be my code? I'm not very experianced with VBA to be honest.

    tia
    Last edited by lawtonl; 10-14-2009 at 05:31 AM.

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Check if named range exists and ignore if it doesn't

    I can't check this but maybe
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-28-2007
    Posts
    6

    Re: Check if named range exists and ignore if it doesn't

    Argh!

    Right I managed to get the code working, although it's a bit of a botched job I must admit using the following code. As I added more code along the same line it hits those If statements and grinds to a halt again with Error 1004

    Please Login or Register  to view this content.
    The line of code that checks for the named range "email" is the same as AccNum, in the fact that there is no data in the workbook at present to be copied yet it bypassed the AccNum If statement, as I want it to if there is no range there and went to the next at when it got to the email If statement and it came up with Error 1004.
    Last edited by lawtonl; 10-14-2009 at 11:23 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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