Deafault Values of Textboxes

bong25

New Member
Joined
Jun 23, 2009
Messages
38
Hi,

I have textboxes in userform and frames, I need to set their default values but not for all of them with the same value,for example:

textbox1 to textbox15 = ""
textbox16 = "common"
textbox17 to 20 = ""
textbox21 = "standard"

Thanks in advance.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
No, I literally have no idea what you're trying to do.

Explain it one more time.
 
Upvote 0
No, I literally have no idea what you're trying to do.

Explain it one more time.

Ahh OK, I have a UserForm in Excel that data entry from Textboxes will fill some areas to cells in sheet1. The userform containes a lot of texboxes some of the area in the userform frames, the idea is once the userform starts, textboxes should be blank and special textboxes has it's own value.

Hope I am clear now.
Thanks

PS:

I found a sample somewhere which is close to what I am trying to achieve:


Dim cCont As Control For Each cCont In Me.MultiPage1.Pages(0).Controls If TypeName(cCont) = "TextBox" Then 'DO STUFF HERE End If Next cCont

But how can I identify the specific textbox number? like textbox1 or 2 or 3 and so on
</pre>
 
Last edited:
Upvote 0
Hello,

What if you were to set the text property to the "start up values"?

go to your userform in the VBE, press F4 if the property window is not showing, find text and enter what you would like. Unless you have a Clear-it-out on initialize....
 
Upvote 0
Here is a line to refer to textboxes on a userform:

<font face=Courier New>UserForm1.TextBox1.Text = "HELLO"</FONT>
 
Upvote 0
This is what I have now, but I was trying to minimize it with loop. But I don't really know how.

Code:
Private Sub UserForm_Initialize()

'Empty TextBox1
TextBox1.Value = ""

'Empty TextBox2
TextBox2.Value = ""

'Empty TextBox3
TextBox3.Value = ""

'Empty TextBox4
TextBox4.Value = ""

'Empty TextBox5
TextBox5.Value = ""

'Empty TextBox6
TextBox6.Value = ""

'EmptyTextBox7
TextBox7.Value = ""

'EmptyTextBox8
TextBox8.Value = ""

'EmptyTextBox9
TextBox9.Value = ""

'EmptyTextBox10
TextBox10.Value = ""

'EmptyTextBox11
TextBox11.Value = ""

'EmptyTextBox12
TextBox12.Value = ""

'EmptyTextBox13
TextBox13.Value = ""

'EmptyTextBox14
TextBox14.Value = "Mr. Name 001"

'EmptyTextBox15
TextBox15.Value = ""

'EmptyTextBox16
TextBox16.Value = ""

'EmptyTextBox17
TextBox17.Value = ""

'EmptyTextBox18
TextBox18.Value = ""

'EmptyTextBox19
TextBox19.Value = ""

'EmptyTextBox20
TextBox20.Value = ""

'EmptyTextBox21
TextBox20.Value = ""

'EmptyTextBox22
TextBox22.Value = ""

'EmptyTextBox23
TextBox23.Value = ""

'EmptyTextBox24
TextBox24.Value = "Mr. Name 002"

'EmptyTextBox25
TextBox25.Value = ""

'EmptyTextBox26
TextBox26.Value = ""

'EmptyTextBox27
TextBox27.Value = "Mr. Name 003"

'EmptyTextBox28
TextBox28.Value = "Mr. B.K. Sundar"

'Empty ComboBox1
ComboBox1.Clear

'Fill ComboBox1
With ComboBox1
    .AddItem "Mr. Name 004"
    .AddItem "Mr. Name 005"
    .AddItem "Mr. Name 006"
    .AddItem "Mr. Name 007"
    .AddItem "Mr. Name 008"
End With

End Sub

Private Sub CheckBox1_Click()
    If CheckBox1.Value And CheckBox2.Value And CheckBox3.Value Then
    CheckBox4.Value = True
    Else
    CheckBox2.Value = False
    CheckBox3.Value = False
    CheckBox4.Value = False
    End If
End Sub

Private Sub CheckBox2_Click()
    If CheckBox1.Value And CheckBox2.Value And CheckBox3.Value Then
    CheckBox4.Value = True
    Else
        CheckBox1.Value = False
        CheckBox3.Value = False
        CheckBox4.Value = False
    End If
End Sub

Private Sub CheckBox3_Click()
    If CheckBox1.Value And CheckBox2.Value And CheckBox3.Value Then
    CheckBox4.Value = True
    Else
        CheckBox1.Value = False
        CheckBox2.Value = False
        CheckBox4.Value = False
    End If
End Sub

Private Sub CheckBox4_Click()
    If CheckBox1.Value And CheckBox2.Value And CheckBox3.Value Then
    CheckBox4.Value = True
    Else
        CheckBox1.Value = False
        CheckBox2.Value = False
        CheckBox3.Value = False
    End If
End Sub

Private Sub OKButton_Click()

Dim emptyRow As Long

'Make Sheet1 Active
Sheets(1).Activate

'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("B:B")) + 1

'Export Data to worksheet
Cells(emptyRow, 2).Value = TextBox1.Value
Cells(emptyRow, 3).Value = TextBox2.Value
Cells(emptyRow, 5).Value = TextBox3.Value
Cells(emptyRow, 6).Value = TextBox4.Value
Cells(emptyRow, 7).Value = TextBox5.Value
Cells(emptyRow, 8).Value = TextBox6.Value
Cells(emptyRow, 9).Value = TextBox7.Value
Cells(emptyRow, 10).Value = TextBox10.Value
Cells(emptyRow, 11).Value = TextBox11.Value
Cells(emptyRow, 12).Value = TextBox8.Value
Cells(emptyRow, 13).Value = TextBox9.Value
Cells(emptyRow, 14).Value = TextBox12.Value
Cells(emptyRow, 15).Value = TextBox13.Value
Cells(emptyRow, 16).Value = TextBox14.Value
Cells(emptyRow, 17).Value = TextBox15.Value
Cells(emptyRow, 18).Value = TextBox16.Value
Cells(emptyRow, 19).Value = TextBox17.Value
Cells(emptyRow, 20).Value = TextBox18.Value
Cells(emptyRow, 21).Value = TextBox19.Value
Cells(emptyRow, 22).Value = TextBox20.Value
Cells(emptyRow, 23).Value = TextBox21.Value
Cells(emptyRow, 24).Value = TextBox22.Value
Cells(emptyRow, 25).Value = TextBox23.Value
Cells(emptyRow, 26).Value = TextBox24.Value
Cells(emptyRow, 27).Value = TextBox25.Value
Cells(emptyRow, 28).Value = TextBox26.Value
Cells(emptyRow, 29).Value = TextBox27.Value
Cells(emptyRow, 30).Value = TextBox28.Value
Cells(emptyRow, 31).Value = ComboBox1.Value


'If CheckBox1.Value = True Then Cells(emptyRow, 4).Value = CheckBox1.Caption
'
'If CheckBox2.Value = True Then Cells(emptyRow, 4).Value = Cells(emptyRow, 4).Value & " " & CheckBox2.Caption
'
'If CheckBox3.Value = True Then Cells(emptyRow, 4).Value = Cells(emptyRow, 4).Value & " " & CheckBox3.Caption
'
'If CheckBox4.Value = True Then Cells(emptyRow, 4).Value = Cells(emptyRow, 4).Value & " " & CheckBox4.Caption

        Dim c As Control
        Dim hasselect As Boolean
        hasselect = False
            For Each c In Frame1.Controls
                If TypeName(c) = "CheckBox" And c.Value = True Then
                    hasselect = True
            Exit For
                End If
            Next c
            
            If hasselect Then Cells(emptyRow, 4).Value = c.Caption Else _
            MsgBox "Come on! Please THICK One!": Exit Sub

Make sure name is entered
If TextBox1.Text = "" Then
    MsgBox "You must enter a year"
    If TextBox2.Text = "" Then
        MsgBox "You must enter a date"
           If TextBox3.Text = "" Then
                MsgBox "You must enter Stock Quantity (Tons)"
                If TextBox4.Text = "" Then
                    MsgBox "You must enter Stock Quantity (BDTons)"
                    If TextBox5.Text = "" Then
                        MsgBox "You must enter Stock Date"
                        If TextBox6.Text = "" Then
                            MsgBox "You must enter the Project Name"
                            If TextBox7.Text = "" Then
                                MsgBox "You must enter the Date"
                                If TextBox10.Text = "" Then
                                    MsgBox "You must enter the Quantity for the Project"
                                    If TextBox11.Text = "" Then
                                        MsgBox "You must enter the Price for the Project"
                                        If TextBox15.Text = "" Then
                                            MsgBox "You must enter the Supplier Name"
                                            If TextBox16.Text = "" Then
                                                MsgBox "You must enter the Supplier Price"
                                                If TextBox17.Text = "" Then
                                                    MsgBox "You must enter the Supplier Date"
                                                    If TextBox25.Text = "" Then
                                                        MsgBox "You must enter Proposed Price"
                                                    Exit Sub
                                                    End If
                                                Exit Sub
                                                End If
                                            Exit Sub
                                            End If
                                        Exit Sub
                                        End If
                                    Exit Sub
                                    End If
                                Exit Sub
                                End If
                            Exit Sub
                            End If
                        Exit Sub
                        End If
                    Exit Sub
                    End If
                Exit Sub
                End If
            Exit Sub
            End If
        Exit Sub
        End If
    Exit Sub
    End If
Exit Sub

                
Unload Me
End Sub



Private Sub CancelButton_Click()

Unload Me

End Sub
I hope you get the idea now.
 
Upvote 0
This may get you started:

<font face=Courier New><SPAN style="color:#00007F">Dim</SPAN> Tloop <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN><br><br>    <SPAN style="color:#007F00">'''Sets textboxes 1 through 13 text to "" on userform1</SPAN><br>    <SPAN style="color:#00007F">For</SPAN> Tloop = 1 <SPAN style="color:#00007F">To</SPAN> 13<br>        <SPAN style="color:#00007F">With</SPAN> UserForm1.Controls("TextBox" & Tloop)<br>        <br>            .Text = ""<br>    <br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> Tloop</FONT>
 
Upvote 0
This may get you started:

Dim Tloop As Integer

'''Sets textboxes 1 through 13 text to "" on userform1
For Tloop = 1 To 13
With UserForm1.Controls("TextBox" & Tloop)

.Text = ""

End With
Next Tloop

Thanks for this, I will try this and let you know.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top