+ Reply to Thread
Results 1 to 11 of 11

Input box to needs different type of variable type (RC vs. A1?)

  1. #1
    Registered User
    Join Date
    01-15-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Input box to needs different type of variable type (RC vs. A1?)

    I'm trying to use an input box to prompt the user to select the row containing the data they want plotted. I am having a problem with the way VBA likes to have its rows and column references formatted (as a letter?) vs. what is returned from selecting an active cell (as a number?).

    Here's the example data that applies:

    Book1.xlsx

    The portion of the code I'm having trouble with comes just after the first If statement.



    Please Login or Register  to view this content.
    Last edited by Niedermee; 08-18-2014 at 01:11 PM. Reason: Fixed asignments in "intStartRow" and "ActiveWorkbook.sheets"

  2. #2
    Registered User
    Join Date
    01-15-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Input box to needs different type of variable type (RC vs. A1?)

    To make this simpler, how do I change the format of the row/column variables in VBA?

    The input box returns a selected cell format as Row 6 when I selected row "H". This is cell is used later in the code, but needs is to be formatted as a letter and not a number so it crashes.

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

    Re: Input box to needs different type of variable type (RC vs. A1?)

    Have you looked at using Cells?
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    01-15-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Input box to needs different type of variable type (RC vs. A1?)

    I don't understand "using Cells".

    I'm a novice at VBA and am trying to change code that originally hard coded the row assignment the same as it currently does for the 1st row.

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

    Re: Input box to needs different type of variable type (RC vs. A1?)

    If you want the user to select a cell/range use this.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-15-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Input box to needs different type of variable type (RC vs. A1?)

    Now it gives me a Compile error: Object Required and highlights Parameter1 before the "="

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

    Re: Input box to needs different type of variable type (RC vs. A1?)

    Strange, that's the error I get if I don't use Set.

    Did you change anything else?

    When you got the error had you selected a range?

    By the way, the reason you should use Set is because Application.InputBox with the Type set to 8 returns a Range object.

  8. #8
    Registered User
    Join Date
    01-15-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Input box to needs different type of variable type (RC vs. A1?)

    In addition to adding "Set" to the Parameter1 assignment, I needed to change the value to an address (Parameter1.address) and then used the mid function to select just the row letter (this assumes I never have any more than Z rows), but it works. See attached.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-15-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Input box to needs different type of variable type (RC vs. A1?)

    How do I mark post as Solved?

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

    Re: Input box to needs different type of variable type (RC vs. A1?)

    Glad it's solved.

    Mind you there's no reason to use Address/Mid to get the row/column number.

    In fact if you do that you may run into problems if the column goes past Z.

    Instead of using Address/Mid you can use the Row and Column properties of Parameter1.

  11. #11
    Registered User
    Join Date
    01-15-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Input box to needs different type of variable type (RC vs. A1?)

    That was what my initial and ultimate goal, but couldn't figure it out. Forgive me if the answer is embedded in someone's reply, but I couldn't get it to work for me.

    How do I "use the Row and Column properties of Parameter1"?

+ 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] multiple conditions to count large amount of data by Type, month & activity type
    By norfolk_lass in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-03-2014, 12:54 PM
  2. Replies: 0
    Last Post: 07-06-2013, 12:59 PM
  3. Proper handling of "cancel" for range-type input box response (type 8)
    By MCCCLXXXV in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-28-2011, 11:19 AM
  4. [SOLVED] Type mismatch using rnge as Range with Type 8 Input Box
    By STEVE BELL in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-03-2005, 01:10 AM
  5. [SOLVED] Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 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