+ Reply to Thread
Results 1 to 6 of 6

How to assign a ImputBox to a "Constant expression"

  1. #1
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    How to assign a ImputBox to a "Constant expression"

    From The Macro I have
    Please Login or Register  to view this content.
    But I want to use a InputBox to assign the number
    Please Login or Register  to view this content.
    But I get the error "Constant expression required" and do not know how to get around this

    Thanks

    The Full Macro:
    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: How to assign a ImputBox to a "Constant expression"

    Hi capson,

    Your following code is not allowed:
    Please Login or Register  to view this content.
    Constants are items that are set in stone. They can be based on other items that are also set in stone, but constants cannot take the value of a variable (even though the value of that variable will never change again).

    Good try, but I think you're stuck with what you have.

    Here is an example of a constant based on another constant:
    Please Login or Register  to view this content.
    Lewis

  3. #3
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    Re: How to assign a ImputBox to a "Constant expression"

    Hello Lewis, thanks you for the reply, not what I wanted to see but I was afriad that would be the case.

  4. #4
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    Re: How to assign a ImputBox to a "Constant expression"

    Lewis if I do this:
    Dim iCnt As Integer

    And Declare iCnt like this:
    Please Login or Register  to view this content.
    I get the proper exactution of the Macro

    But if I Declare iCnt like this:
    Please Login or Register  to view this content.
    The Macro gives the wrong output

    Can this be trusted to give the proper output
    Please Login or Register  to view this content.
    Last edited by capson; 12-26-2014 at 11:06 AM.

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: How to assign a ImputBox to a "Constant expression"

    Both your constructions work fine if the input data is valid. The 'M6' construction will give you trouble if the value is NOT a number. You probably need to employ some defensive programming techniques with that one to make sure that nothing will go wrong, go wrong, go wrong.

    Please NOTE that 'Sheets(1)' always uses the sheet that is the first tab (all the way on the left). Many programmers prefer the method you use. My personal preference is to use 'Sheets("SheetX")' or whatever the actual 'Sheet Name' is.


    See the following examples which use your code exactly as is (tested and working):
    Please Login or Register  to view this content.
    You may also want to check to make sure iCnt is in the expected range.

    Lewis

  6. #6
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    Re: How to assign a ImputBox to a "Constant expression"

    Thank you, I will implement this

+ 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: 5
    Last Post: 11-04-2013, 11:28 AM
  2. [SOLVED] Find expression causing "Subscript out of range" error
    By aseret in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-08-2013, 12:05 AM
  3. [SOLVED] Assign Categories for Time of Day: "Morning", "Afternoon", "Evening"
    By long_shanks in forum Excel General
    Replies: 3
    Last Post: 06-11-2013, 02:59 AM
  4. Replies: 4
    Last Post: 03-02-2012, 02:17 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