+ Reply to Thread
Results 1 to 20 of 20

Use Numerical Value from a TextBox as Input for a Formula

  1. #1
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Use Numerical Value from a TextBox as Input for a Formula

    Hello Excel experts,


    I want to know what I Need to do declare and use a TextBox I want to add in a UserForm, so that the numerical value entered in this field will be the value to use for a formula.

    This is the Code for the calculation:

    With Cells(1, Columns.Count).End(xlToLeft).Offset(, 1)
    .Resize(, 2).Value = Array("Average", "25% Average")
    .Offset(1, 0).Resize(LastRow - 1).FormulaR1C1 = "=AVERAGE(RC2:RC[-1])"
    .Offset(1, 1).Resize(LastRow - 1).FormulaR1C1 = "=RC[-1]*REFERENCEVALUE"
    .Resize(, 2).EntireColumn.NumberFormat = "0.0000"
    End With


    I would like the user to be able to modify the value that will multiply RC[-1], that means "REFERENCEVALUE".
    So the question is, how can I create the TextBox that will give me the value "REFERENCEVALUE" that the user can enter?

    Thank you very much in advance and I hope I was clear enough.

    Jorge

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Use Numerical Value from a TextBox as Input for a Formula

    Please Login or Register  to view this content.
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Re: Use Numerical Value from a TextBox as Input for a Formula

    Hello,

    Could you please explain me more?
    I didnt quite get it.

  4. #4
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Re: Use Numerical Value from a TextBox as Input for a Formula

    It is not an Input box what I want to do, but being able to Input that reference value via TextBox in a UserForm.

  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: Use Numerical Value from a TextBox as Input for a Formula

    Jorge

    Assuming this code is in the userform and the textbox is called txtRefNo all you should need is something like this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Re: Use Numerical Value from a TextBox as Input for a Formula

    I tried to just Change the TextBox Name to txtRefNo and give t a try but it doesnt work.

    The Code for that calculation is not in the Userform but in a Module, does that have something to do?

    There are many Things I still dont get since Ive just been learning myself recently.

    Thanks again,
    Jorge

  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: Use Numerical Value from a TextBox as Input for a Formula

    Jorge

    If the code for the formula is in a module you would need to reference the userform as well.

    So assuming the userform is called UserForm1.
    Please Login or Register  to view this content.
    Note, this will only work if the userform is loaded when you run this code.

  8. #8
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Re: Use Numerical Value from a TextBox as Input for a Formula

    Hello Norie,

    I tried that but ist not working, I dont know what I am doing wrong.

    This is how it Looks now, which is inside a Module:

    Please Login or Register  to view this content.
    My TextBox Code is in the Userform Module, but I donīt know how to declare/reference it, to adopt the value the user enters, this is what I have:

    Please Login or Register  to view this content.
    Which Im almost sure it is wrong, but I have no idea what to Change.

    Could you help me?

    Thanks.
    Jorge
    Last edited by jorgeflores; 01-18-2018 at 09:34 AM. Reason: Did not use code tags

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

    Re: Use Numerical Value from a TextBox as Input for a Formula

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  10. #10
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Re: Use Numerical Value from a TextBox as Input for a Formula

    I am sorry about that. Will not happen from now on!

    Jorge

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

    Re: Use Numerical Value from a TextBox as Input for a Formula

    No problem.

    Try this.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Re: Use Numerical Value from a TextBox as Input for a Formula

    I Dont know why but it still does not work, I get an error on this line:

    Please Login or Register  to view this content.
    The UserForm is called UserForm1 and TextBox is called txtRefNo.

    Is this the correct way to "declare" the TextBox and what happens when the user Inputs info?

    Please Login or Register  to view this content.
    Thanks again and sorry for being such a pain. but ist a Project that could really get me some Points at work to get a full time contract.

    Jorge

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

    Re: Use Numerical Value from a TextBox as Input for a Formula

    Jorge

    What error message do you get?

    PS You don't need anything like this.
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Re: Use Numerical Value from a TextBox as Input for a Formula

    Hello Norie,

    I already deleted the Code for the TextBox

    Please Login or Register  to view this content.
    and the error I get is Error 1004 "Application-defined or Object-defined error", marking the line:

    Please Login or Register  to view this content.
    I dont know what else I could try then.

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

    Re: Use Numerical Value from a TextBox as Input for a Formula

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED, scroll down and click Manage Attachments.

  16. #16
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Re: Use Numerical Value from a TextBox as Input for a Formula

    Hello Norie, I just attached a sample of the file.

    I think a short Explanation might help. Each column is a solar panek, each row is a date/time and values are for curent that the Panel generates. The reason of my Project is to get the average of every line and then multiply that average
    times a value the user can enter (the TextBox in the UserForm) this to find the Panels that provide less current than
    some references that we have.

    The line that Shows the error is in Module 1.

    I really appreciate your help.
    Jorge
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Re: Use Numerical Value from a TextBox as Input for a Formula

    Hello Norie,

    Sorry to bother you, did you have by any Chance the opportunity to take a look at the file?

    Thank you very much in advance.

    Jorge

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

    Re: Use Numerical Value from a TextBox as Input for a Formula

    Jorge

    Apologies, didn't see you had uploaded a file - don't have a chance to look at it now but I will later.

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

    Re: Use Numerical Value from a TextBox as Input for a Formula

    This worked for me when it was called from the userform.
    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Re: Use Numerical Value from a TextBox as Input for a Formula

    Hello again Norie!

    Thank you for your responde, sorry if I sound too ignorant... what does "called" from the userform mean? That the sub Averages code is in the Userform Module?

    Jorge

+ 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] How to set user input in a textbox to Currency
    By rodalsa1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-08-2015, 12:03 PM
  2. Convert User Form textbox entry to numerical value
    By MeBeMel in forum Excel General
    Replies: 1
    Last Post: 05-12-2014, 12:19 AM
  3. input the value of a Combobox and a textbox to a TEXTBOX directly from a userform
    By Gordonhk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-11-2013, 03:25 PM
  4. Replies: 1
    Last Post: 02-06-2013, 05:00 PM
  5. Use textbox input and VLookup to update another textbox on same userform
    By gcoug in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-22-2011, 10:39 AM
  6. How to format TextBox output as numerical
    By knarf in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-15-2009, 02:52 PM
  7. How to set user's input in textbox to be numerical?
    By Chwa See Kiap in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-05-2006, 05:15 AM

Tags for this Thread

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