+ Reply to Thread
Results 1 to 7 of 7

VBA Autofill text box

Hybrid View

  1. #1
    Registered User
    Join Date
    10-31-2012
    Location
    Fargo
    MS-Off Ver
    Excel 2010
    Posts
    17

    VBA Autofill text box

    I am pretty new to programming and I sure this isn't that complicated but I can't find anything to tell be how to do it so hopefully someone here can help. I am putting together a user form that will draw off a workbook to build a quote that can be given to customers. What I need for now is when I check a box I need the textbook in the form to autopopulate with an assigned text. Example I have domestic and export machines. I have two checkboxes. One reads Domestic and one Export. If this is an export machine and I check that box I need the message box next to it to display "Non Assembled Unit". Likewise if I check domestic it should read "Fully Assembled". If both are are selected or neither are selected the text box should read select one.

    Thanks

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA Autofill text box

    Here is the basic format. This will have to be saved in the userform module. You will also have to change the names of the checkboxes/textboxes etc to match the names you set up in your userform. A separate but similar sub will have to be created for your other checkboxes.
    Private Sub CheckBox1_Click()
        If CheckBox1.Value = True Then
            textbox1.Value = "Domestic"
        ElseIf CheckBox1.Value = False Then
            textbox1.Value = ""
        End If
    End Sub
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    10-31-2012
    Location
    Fargo
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: VBA Autofill text box

    Thank you. A secondary question to this is how do I get it to automatically fill the information up. Right now I have to click on the text box and hit a key as if I was going to enter data manually and then it will override what I type and enter the data the it was supposed to autofill.

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA Autofill text box

    The code above should automate everything when the checkbox is clicked. Did you place the code in the userform module?

    Can you attach your workbook so we can make adjustments?

  5. #5
    Registered User
    Join Date
    10-31-2012
    Location
    Fargo
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: VBA Autofill text box

    I attached it. As you can see

    Private Sub CommandButton1_Click()
        TextBox2 = Format(Val(TextBox1) + Val(TextBox3), "Currency")
    End Sub
    
    Private Sub TextBox1_Change()
                If CheckBox1.Value = True Then
                TextBox1.Value = "1"
                ElseIf CheckBox1.Value = False Then
                TextBox1.Value = ""
                End If
    End Sub
    
    Private Sub TextBox2_Change()
    
    End Sub
    
    Private Sub TextBox3_Change()
            If CheckBox2.Value = True Then
            TextBox3.Value = "2"
            ElseIf CheckBox2.Value = False Then
            TextBox3.Value = ""
            End If
    End Sub
    
    Private Sub UserForm_Activate()
    
    End Sub
    
    Private Sub UserForm_Click()
    
    End Sub
    I have three text boxes and two check boxes. When I select the checkbox it is supposed to display the value assigned to the textbox. The end goal is going to be that when you select checkbox one it will give you a price in one textbox and notes in a yet to be added textbox next to it therefore creating a pricing sheet. I am just in the beginning stages of experimentatio Then which is why I changed them to numeric resposonses and added a calculate button as opposed to the text that I gave you in the post. But when I check checkbox1 textbox 1 doesn't automatically go to 1 until I type something in it which is where my problem currently lies.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    10-31-2012
    Location
    Fargo
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: VBA Autofill text box

    Sorry the attached one had some extra code in it from an old experiment I deleted it and brought it back to what I orginally had. Open the smaller of the two attached files the code in it should match what I had posted.
    Attached Files Attached Files

  7. #7
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA Autofill text box

    Private Sub Checkbox1_Change()
                If CheckBox1.Value = True Then
                TextBox1.Value = "1"
                ElseIf CheckBox1.Value = False Then
                TextBox1.Value = ""
                End If
    End Sub
    Private Sub Checkbox2_Change()
            If CheckBox2.Value = True Then
            TextBox3.Value = "2"
            ElseIf CheckBox2.Value = False Then
            TextBox3.Value = ""
            End If
    End Sub

+ 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. Autofill a template with text or numbers?
    By Pontooner in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-07-2013, 05:22 PM
  2. Replies: 11
    Last Post: 12-10-2012, 10:40 AM
  3. Autofill between two Text defined cells
    By markbrunstad87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2012, 01:45 AM
  4. AutoFill mixed text and numbers
    By fandangle in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 12-01-2007, 09:13 AM
  5. autofill with number embedded in text
    By beckstei in forum Excel General
    Replies: 1
    Last Post: 05-25-2006, 12:30 PM

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