+ Reply to Thread
Results 1 to 7 of 7

text box input to store as a variable?

  1. #1
    Forum Contributor
    Join Date
    05-09-2009
    Location
    Chicago, US
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    188

    text box input to store as a variable?

    I have a simple (I think) question. I drew a TextBox in my excel sheet, and I would like that after I enter something into it, lets say for ex "59"...I'd like for that text to be then stored as a variable ("number").

    Then I'd like to perform some calculations with that variable. For instance:

    Range("A1").Value = 14 + number


    and I would like A1 to then show 73 ((14 + 59 (or whatever was entered into the text box))

    Is this possible?

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: text box input to store as a variable?

    Quote Originally Posted by losmi8 View Post
    I have a simple (I think) question. I drew a TextBox in my excel sheet, and I would like that after I enter something into it, lets say for ex "59"...I'd like for that text to be then stored as a variable ("number").

    Then I'd like to perform some calculations with that variable. For instance:

    Range("A1").Value = 14 + number


    and I would like A1 to then show 73 ((14 + 59 (or whatever was entered into the text box))

    Is this possible?
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: text box input to store as a variable?

    Yes, it's possible; but I really can't understand why you'ld want to do it that way.

    You could do something with the textbox change event and also with the worksheet change event.

    e.g., If your worksheet was named Sheet1 and the ActiveX textbox on sheet1 was was called TextBox1 the following code would change the value in A1 to be whatever the value in A1 + the value in TextBox1 was.


    Please Login or Register  to view this content.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: text box input to store as a variable?

    Hi losmi8
    This code is similar to jrdnoland's
    Please Login or Register  to view this content.
    .
    I've assumed your "14" was from another location ("C1") in the code; the code also clears TextBox1 when you tab out of TextBox1 (the tab key actually fires the code).
    Hope this helps. John
    Last edited by jaslake; 12-05-2009 at 11:58 PM.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Forum Contributor
    Join Date
    05-09-2009
    Location
    Chicago, US
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    188

    Re: text box input to store as a variable?

    Thanks for the responses guys! What if I need the value from the textbox to be used in another Sub() below it?

    I will try this code later and see if I am able to combine it with the existing code I have now.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: text box input to store as a variable?

    Hi losmi8
    This code will pass the value of TextBox1 (x) to procedures in the same module.

    Please Login or Register  to view this content.
    Hope this helps. John

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: text box input to store as a variable?

    Hi losmi8
    I should have explained that
    This code will pass the value of TextBox1 (x) to procedures in the same module
    and will remain available in the module until an End statement is executed.
    John

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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