+ Reply to Thread
Results 1 to 4 of 4

Transfer data from userform to macro in a module, and textbox input as numbers?

  1. #1
    Registered User
    Join Date
    05-22-2014
    Posts
    37

    Transfer data from userform to macro in a module, and textbox input as numbers?

    Hi.
    I have a user form with 3 text boxes. In all of these are there numbers to be entered.
    I then use the input to insert in a sheet with formulas which uses the inputs. But after the macro is run, I see a yellow triangle that tells me the cell is formatted as text. As I have another macro running tests with the numbers, it is too late to convert the cells afterwords. I have to convert them in the user form or maybe at the start of the macro?
    How do I do that?
    I have experienced that formulas using cells (with numbers) formatted as text can mess things up (without giving a warning, in other words without sending an error message...! And that is dangerous!

    Anyways, here is the background for what I do;
    I would really like to "transfer" a input from the textbox in the user form directly to a macro in a module, but I don't know how so instead I use cell "P1" as a temporary range, saying in the sub button_click (in userform) that range("P1")=textbox1.value then call macro1. And in macro1 I say numberIwant=range("P1"). But this gives me sometimes weird answers (and always formatting the cell to text).
    Please help me with either formatting or to transfer the number from the textbox in userform to a macro in a module.

    Thanks in advance!!!!

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Transfer data from userform to macro in a module, and textbox input as numbers?

    You did not attach a sample, but to write the values from the form's textboxes you can use something like:
    Range("A1").Value = CDbl(textboxX.Value) to convert the text data to an Excel numeric value. Use CDbl if you have decimal values and CLng if it's alway whole (integer) values.
    Ben Van Johnson

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Transfer data from userform to macro in a module, and textbox input as numbers?

    Here's a great resource for how to pass and use the data from your userform: http://peltiertech.com/Excel/PropertyProcedures.html

  4. #4
    Registered User
    Join Date
    05-22-2014
    Posts
    37

    Re: Transfer data from userform to macro in a module, and textbox input as numbers?

    Thanks you guys!!
    ProtonLeah; it worked perfect!!!
    jomili; thanks, read it. But I (as a noobie) find this link easier to understand :-)
    http://stackoverflow.com/questions/2...-module-in-vba

    Anyways, thanks for helpful and quick answers!!!

+ 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] Transfer data from userform textbox to spreadsheet
    By markusvirus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-22-2015, 10:11 AM
  2. [SOLVED] How to restrict textbox input with module?
    By alee001 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-26-2014, 04:16 AM
  3. Transfer listbox and textbox data from userform to spreadsheet
    By NellieNoggs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-05-2014, 02:35 PM
  4. [SOLVED] Userform Macro to Use Textbox input to Generate blank rows.
    By jaredmccullough in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 04-02-2014, 01:21 PM
  5. [SOLVED] Userform only to input data to Sheet only if textbox contains data/number.
    By BPSJACK in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-31-2012, 11:30 AM
  6. Userform Textbox to input data to worksheet
    By wrobs in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-23-2010, 01:02 AM
  7. Find UserForm ComboBox Value (date) & Transfer TextBox Data To Same Row
    By okriskao in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2008, 11:33 AM

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