Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    May 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Paste string from input box (Excel 97 SR-1)

    I have created an input box for the user to return a number. Below is my code, for your amusement:

    Dim Message, Title As String
    Dim QuoteValue As Integer

    Message = "What is the new quote number?"
    Title = "New quote number"
    QuoteValue = InputBox(Message, Title)

    Here's my question...I want the value of the input to be returned to A2 on the activesheet...for the life of me I can't figure out how to do it. For those of you out there who are actually developers and are cringing at the naiveness of this question, I apologize. I'm actually a network administrator who got slapped with some programming duties.

    I appreciate any help anybody can give me.

    Adam Roehm
    roehmadam@yahoo.com

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Paste string from input box (Excel 97 SR-1)

    It doesn't matter if you question is easy. We all had to learn once - and are still learning.

    Range("A2") = QuoteValue

    will set the value of cell A2 on the active sheet to the value of QuoteValue.

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Paste string from input box (Excel 97 SR-1)

    Try

    Dim Message, Title As String
    Dim QuoteValue As String
    Message = "What is the new quote number?"
    Title = "New quote number"
    QuoteValue = InputBox(Message, Title)
    If QuoteValue <> "" Then
    Range("A2") = Quote
    End If

    I have set QuoteValue as a string so that errors can be trapped easier. Non numeric entriies will return 0 (zero).

    Andrew C

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Paste string from input box (Excel 97 SR-1)

    <P ID="edit" class=small>Edited by HansV on 06-May-02 18:22.</P>As an alternative, you can use the InputBox method of the Application object:

    <pre>QuoteValue = Application.InputBox(Prompt:="What is the new quote number", Type:=1)</pre>

    will only accept numeric input.

    Added: oops, JohnBF was a bit faster...

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Paste string from input box (Excel 97 SR-1)

    ... and as I just edited, you might want to make that Integer a Double, depending on the maximum size of QuoteValue!
    -John ... I float in liquid gardens
    UTC -7ąDS

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Paste string from input box (Excel 97 SR-1)

    Good point, Hans

    Andreww

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Paste string from input box (Excel 97 SR-1)

    Since someone, possibly you, Andrew, showed my the InputBox Method, I use it nearly exclusively.
    -John ... I float in liquid gardens
    UTC -7ąDS

  8. #8
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Paste string from input box (Excel 97 SR-1)

    This should get you started. Note that VBA Dims have to be made for each variable or they default to Variant. If you want to post more detail about the entire task, we can maybe help improve this.

    Dim strMessage As String, strTitle As String
    Dim dblQuoteValue As Double

    strMessage = "What is the new quote number?"
    strTitle = "New quote number"

    ' comment - setting the last parameter sets the input type, in this case numeric
    dblQuoteValue = Application.InputBox(strMessage, strTitle, , , , , , 1)
    ActiveSheet.Range("A2").Value = dblQuoteValue

    etc ...

    Other Types for the Inputbox are:
    Value Meaning
    0 A formula
    1 A number
    2 Text (a string)
    4 A logical value (True or False)
    8 A cell reference, as a Range object
    16 An error value, such as #N/A
    64 An array of values
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •