+ Reply to Thread
Results 1 to 8 of 8

Excel 2007 : Out of range error

  1. #1
    Registered User
    Join Date
    12-24-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    89

    Out of range error

    Morning,

    In worksheet, Solemn c3:c26 are dates. I created an array to contain these dates, called myArray.

    In worksheet Sheet3 a1 is a date. Idea is to check if Sheet3 a1 is contained in the array.

    Simple enough...for most, but I get an "Subscript out of range" error. My understanding or that error is that it is usually caused by a typo, or non-existance of a worksheet.

    I've double, triple, quadruple, checked spellings, etc. Can't get rid of the error!

    Would someone take a look at the code and see what it is that I messed up?

    Please Login or Register  to view this content.
    Last edited by BigGPL; 02-14-2011 at 07:14 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Out of range error

    Would you be able to explain where the error occurs?

  3. #3
    Registered User
    Join Date
    12-24-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Out of range error

    Quote Originally Posted by davesexcel View Post
    Would you be able to explain where the error occurs?
    Hey Dave,

    If I checked correctly, Debug>Step Into, everytime it steps from the line:
    Set myRng1 = Worksheets(Solemn).Range("c3:I26")

    That is when the error box appears.

    I've attached a stripped down workbook
    Attached Files Attached Files

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

    Re: Out of range error

    The code should be in a Standard module, not the WorkBook module

    This
    Please Login or Register  to view this content.
    Should be

    Please Login or Register  to view this content.
    myRng1 is not declared, should be declared as a Range
    myLookUp is not declared

    What are you trying to do exactly? I can't see why you have the array nor the purpose of the code
    Last edited by royUK; 02-13-2011 at 09:16 AM.
    Hope that helps.

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

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    12-24-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Out of range error

    Quote Originally Posted by royUK View Post
    The code should be in a Standard module, not the WorkBook module

    This
    Please Login or Register  to view this content.
    Should be

    Please Login or Register  to view this content.
    myRng1 is not declared, should be declared as a Range
    myLookUp is not declared

    What are you trying to do exactly? I can't see why you have the array nor the purpose of the code
    First of all I have to tell you that I am releatively new to Excel.
    The purpose of the code is to check if today's date (Sheet3 A1) is in the list of dates in the sheet Solemn C3:C26. If it is then need to get the info from the row that corresponds to the matched date in Sheet3 to display in Main D2.

    As mentioned, I'm a newbie, so if there is an easier way to check the dates I would really be grateful for some code.

    BTW, Thanks for the reply.

    George

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

    Re: Out of range error

    Not sure why you need VBA. It looks to me that the dates in the Table are not actual dates that Excel will recognise, but Text

  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: Out of range error

    Here's how to do this with formulas
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    12-24-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Out of range error

    Hey Roy,

    Thanks for your help in this matter, and thanks for the worksheet formula.
    The Resaon for the vba is that when the workbook opens Today() is checked against the list of Solemn days, if its not in that list then it is checked to see in what Liturgical season the date falls, and then it is checked to see if Today() is a Sunday.

    When all the above checking is completed the appropriate information for Today() is then displayed.

    I got everything working, more or less, but the subscript out of range error. You hit upon it when you mentioned the dates were TEXT. I forgot about that. So I changed the dates to their number equivalents , ie, April 24, 2011 is 40657. Today() is in Sheet3 A1 and A1 of worksheet Solemn = Sheet3!A1 with the cell formated as number. It works.

    Again, thanks to all who replied.

    My code:

    Please Login or Register  to view this content.
    George

+ 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