+ Reply to Thread
Results 1 to 7 of 7

completely flummoxed by the InputBox

  1. #1
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Pendleton, OR
    MS-Off Ver
    Excel 2013
    Posts
    129

    completely flummoxed by the InputBox

    I have code to Copy and Paste columns of data based on a value in one cell. The user is to input the range of values for that cell, so I have the following lines


    lower_limit = InputBox("lower OD limit")
    upper_limit = InputBox("upper OD limit")

    However, whatever value is in the cell will give True to < upper_limit and False to > lower_limit
    MsgBox will show these limits as being assigned correctly, and they are declared as Single but do not seem to be being read as numbers/

    If I set the values via

    lower_limit = 0.15
    upper_limit = 0.6

    everything runs fine. Any clue what I have missed, or misused in the InputBox ?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: completely flummoxed by the InputBox

    The values returned by an input box are strings but they should convert to numeric if assigned to variables that are declared with a numeric data type.

    How are you comparing the values from the input boxes to the values in the cells?

    Are the values in the cells numeric?

    PS If the user is entering column numbers you should probably use Long (integer) rather than Single (decimal).
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Pendleton, OR
    MS-Off Ver
    Excel 2013
    Posts
    129

    Re: completely flummoxed by the InputBox

    The values in the cells are numeric and all the rest of the code works with the values assigned in the code. I thought I had found the solution, adding all the parameters to the InputBox and ending with a 1 (numeric), but I keep getting the message that the InputBox function has the wrong number of parameters, though they match what I see in Microsoft's help file.

    OK...I have drifted into the twilight zone. My attempt to reply was blocked because it was deemed to contain HTML code ???

  4. #4
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Pendleton, OR
    MS-Off Ver
    Excel 2013
    Posts
    129

    Re: completely flummoxed by the InputBox

    When I finally got an acceptable number of parameters
    lower_limit = InputBox("lower OD limit", , , , , , 1)
    I got the error message that it was an invalid procedure call, which seems reasonable since it seems like there are too few parameters. I will have to check the other parameters.

  5. #5
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Pendleton, OR
    MS-Off Ver
    Excel 2013
    Posts
    129

    Re: completely flummoxed by the InputBox

    When I include 8 arguments (as per Microsoft Excel VBA help) I get this message
    Compile error:
    Wrong number of arguments or invalid property assignment
    If I use one less argument and write lower_limit = InputBox("lower OD limit", "low", 0.15, , , , 1) I get the following
    Run-time error '5':
    Invalid procedure call or argument
    I get the feeling I am missing something obvious.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: completely flummoxed by the InputBox

    I think you might be looking at the help for the wrong (type of?) input box.

    In Excel VBA there are 2 input boxes, there's the standard VBA InputBox and the Excel specific Application.InputBox.

    The former takes 5 arguments - Prompt, Title, DefaultResponse, Xpos and YPos. and returns a String value

    The latter takes 8 arguments - Prompt , Title , Default , Left , Top , HelpFile , HelpContextID , Type and returns a Variant.

    If you just want the user to enter the no of a column I would suggest using the former, if you want them to actually select the columns via the input box I would suggest the latter.

  7. #7
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Pendleton, OR
    MS-Off Ver
    Excel 2013
    Posts
    129

    Re: completely flummoxed by the InputBox

    That was exactly right. I was confused by the InputBox function and the InputBox method (where I was reading the help)

    Two solutions :

    Continue with the InputBox function and multiply the values by 1 before entering into the inequalities

    OR

    Use Application.InputBox("prompt", Type:=1)

    In either case I get numerical values.

    Thanks for your help. I will 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] MACRO: If user clicks cancel in inputbox,then do nothing. Problem with inputbox appearance
    By Tona in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-05-2015, 04:33 AM
  2. [SOLVED] Inputbox vs. Application.InputBox
    By miyachow in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-08-2013, 12:53 PM
  3. [SOLVED] If inputbox = false then repeat inputbox
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-28-2013, 01:27 PM
  4. InputBox-ow to have a user input text in a inputbox
    By noodle48 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2011, 08:17 AM
  5. Screen positioning inputbox that is set as Application.InputBox
    By vdongen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-06-2010, 07:59 AM
  6. InputBox-Is it possible to put 2 question in one InputBox ?
    By Shark Man in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-23-2009, 12:04 AM
  7. Inputbox button control + msgbox for empty inputbox
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-30-2009, 12:39 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