+ Reply to Thread
Results 1 to 4 of 4

Compile Error: Constant Expression required problem

  1. #1
    Registered User
    Join Date
    02-13-2020
    Location
    hull, england
    MS-Off Ver
    2007
    Posts
    32

    Compile Error: Constant Expression required problem

    Hi

    I am trying to generate a random unique number with the following code. The MAX value will be dependant on the number of used rows in another worksheet so Iv tried to allow for this as you can see in the code below.
    The problem I have is I'm getting a Compile Error: Constant Expression required.
    Iv looked through Google but to be honest a lot of it is over my head.
    Could someone help me out please?

    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Compile Error: Constant Expression required problem

    When you declare a Const, its value must be determined at compile time. You are using LastRow which is a variable that is not determined until runtime. You must declare MAX as a variable instead of a Const.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    02-13-2020
    Location
    hull, england
    MS-Off Ver
    2007
    Posts
    32

    Re: Compile Error: Constant Expression required problem

    Cheers mate, thankyou very much

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Compile Error: Constant Expression required problem

    You're welcome!

    If a member helped you solve your problem, consider adding to their reputation by clicking on the star icon addreputationiconsmall.jpg below their name.

+ 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. Compile Error: compile error constant expression required.
    By countryfan_nt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2019, 04:45 AM
  2. VBA - Enumeration Bugs "Constant Expression Required"
    By ironfelix717 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-27-2019, 06:38 PM
  3. [SOLVED] "constant expression required" error given when setting up an array
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-27-2017, 12:06 PM
  4. [SOLVED] Compile Error Constant Expression Required
    By dloskot in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-10-2016, 02:46 PM
  5. Compile Error: Expected expression
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-14-2016, 02:33 PM
  6. Compile error (Constant expression required) when using macro twice
    By flunzy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-02-2014, 10:35 AM
  7. [SOLVED] Compile error: Constant expression required error when merging two Codes
    By Kezwick in forum Outlook Programming / VBA / Macros
    Replies: 8
    Last Post: 06-26-2013, 09:32 AM

Tags for this Thread

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