• Obtaining Cell Address from Input Box (Excel XP)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Obtaining Cell Address from Input Box (Excel XP)

    Author
    Topic
    #378995

    Please forgive me if I am asking a question that has been posted before; I did a search and couldn’t find anything that directly related to my issue.

    Basically what I am trying to do is to capture a specific address from an Excel Input Box (as opposed to the VBA type). Here is the code I am using:

    Set RInput = Application.InputBox _
    (Prompt:=”Enter the Row Input Cell:”, _
    Title:=”Row Input Cell”, _
    Type:=8)

    What I want RInput to return is the cell address the user either types or clicks (it would be a single cell). Instead it is returning the contents of the cell.

    What am I doing wrong?

    Viewing 1 reply thread
    Author
    Replies
    • #629370

      the address is:

      Rinput.address

      Note: It is not JUST a single cell. They could highlight a RANGE of cells.

      Steve

      • #629372

        Thank you very much. I just could not see it.

      • #629392

        Steve,

        Your suggestion didn’t work. I get “Assignment to Constant nor Permitted” errors. When I comment out the Dim (I had dimmed RInput as Range), that error goes away, but then I get a run time error that says “Object required”.

        Any ideas?

        Thanks,

    • #629397

      range.Address is a string, so:

      Dim rInput As Range
      Dim sAddress As String
      Set rInput = Application.InputBox _
      (Prompt:=”Enter the Row Input Cell:”, _
      Title:=”Row Input Cell”, Type:=8)
      sAddress = rInput.Address
      MsgBox sAddress

      you’ll have to discard the part of the string after the “:” to get the first selected cell or row or column number if a multicell range is selected.

      • #629401

        John,

        Your routine works perfectly. Thanks so much.

        Regards,

        • #629403

          No problem, and here’s the line to trim to the first cell in the range:

          If InStr(2, sAddress, “:”) Then sAddress = Left(sAddress, InStr(2, sAddress, “:”) – 1)

          (I was trying to use

          If InStr(2, sAddress, “:”) Then sAddress = Split(sAddress, “:” , 1,vbTextCompare)

          but I get type mismatch, can someone tell ME what is wrong with the latter line?)

          • #629406

            I’ll try your suggestion tomorrow as I have to run now. I thank you again for your help and your insights.

            I’ll let you know how it all comes out.

            Regards,

          • #629411

            Ah. I return much wiser from the VBA forum, thanks once again Andrew for post 185657. Split takes a string but returns an array of strings, so it’s necessary to specify that only the first element is returned:

            sAddress = Split(sAddress, “:”)(0) ‘is all that’s needed

        • #629512

          Not to ask a stupid question, but why do you want the address when you already have the range? It would probably be better to use the range in whatever subsequent code that you write. –Sam

      • #629475

        Or use rInput.Cells(1,1).Address

        Gives you the first cell of the first area a user has selected, whereas:

        rInput.Areas(2).Cells(2,1) gives the cell on the second row of the first column of the second area the user selected.

    Viewing 1 reply thread
    Reply To: Obtaining Cell Address from Input Box (Excel XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: