UserForm for data entry: force certain controls to be filled in.

Aretradeser

Board Regular
Joined
Jan 16, 2013
Messages
173
Office Version
  1. 2013
Platform
  1. Windows
A Userform, used as a form for data entry, consists of several TextBoxes and ComboBoxes for data entry.
By means of these VBA code lines some of them are forced to be filled in:
CODE:
VBA Code:
    If ComboBox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
        ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
        TextBox5 = Empty Or TextBox6 = Empty Or TextBox7 = Empty Then
        MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
    Else

The problem occurs when in the ComboBox1 an element other than "SPAIN" or "PORTUGAL" is selected, which disables the ComboBox6 and the TextBox7; as they cannot be filled in, the data cannot be recorded.
How to solve this obligation to fill in when these controls are disabled (ComboBox6 and TextBox7).
 
ok

so i would think this would work for you?

VBA Code:
Private Sub cmdbRegistrar_Click()
    Dim Salir As Boolean
    Dim fe1 As Date
    Dim fe2 As Date

If combobox1 = "SPAIN" Or combobox1 = "PORTUGAL" Then
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Or TextBox6 = Empty Or TextBox7 = Empty Then
    MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
Else
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Then
    MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
End If

        fe1 = CDate(TextBox1)
        TextBox1 = Format(fe1, "mm/dd/yyyy")
        If Not IsDate(TextBox2) Then
            MsgBox "INGRESE UNA FECHA VÁLIDA", vbExclamation
            TextBox2.SetFocus
            Exit Sub
        End If
        fe2 = CDate(TextBox2)
        TextBox2 = Format(fe2, "mm/dd/yyyy")
        Sheets("BDATOS").Select
        Sheets("BDATOS").Unprotect ("123")
        With Worksheets("BDATOS")
            Cells(t + 1, 2) = TextBox6 & " " & TextBox7 & ", " & TextBox5
            Cells(t + 1, 3) = ComboBox5
            Cells(t + 1, 4) = ComboBox5 '
            Cells(t + 1, 5) = combobox1 '
            Cells(t + 1, 6) = ComboBox2
            Cells(t + 1, 7) = TextBox1.Value
            Cells(t + 1, 8) = TextBox2.Value
            Cells(t + 1, 9) = ComboBox3
            Cells(t + 1, 10) = ComboBox4
            Cells(t + 1, 11) = 0 + TextBox3
            Cells(t + 1, 12) = TextBox4.Value
            Cells(t + 1, 13) = CmbSexo
            Cells(t + 1, 14) = Right(TextBox1.Value, 4)
        End With
        Cells(t, 13).Select
        Selection.AutoFill Destination:=Range("M" & t & ":M" & t + 1), Type:=xlFillDefault
        Sheets("BDATOS").Protect ("acuario3511")
        For n = 1 To 12
            On Error Resume Next
            Controls("textbox" & n) = ""
            Controls("combobox" & n) = ""
        Next
        Sheets("DATOS").Select
        Cells.Select
        Cells.EntireColumn.AutoFit
   
End Sub
It does not work. It still requires the completion of all controls.
Also, your code was missing an End If block.
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
end if, ok the i did spot an error based on that.

try the below, im going to test it properly


VBA Code:
Private Sub cmdbRegistrar_Click()
    Dim Salir As Boolean
    Dim fe1 As Date
    Dim fe2 As Date

If combobox1 = "SPAIN" Or combobox1 = "PORTUGAL" Then
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Or TextBox6 = Empty Or TextBox7 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
Else
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
End If

        fe1 = CDate(TextBox1)
        TextBox1 = Format(fe1, "mm/dd/yyyy")
        If Not IsDate(TextBox2) Then
            MsgBox "INGRESE UNA FECHA VÁLIDA", vbExclamation
            TextBox2.SetFocus
            Exit Sub
        End If
        fe2 = CDate(TextBox2)
        TextBox2 = Format(fe2, "mm/dd/yyyy")
        Sheets("BDATOS").Select
        Sheets("BDATOS").Unprotect ("123")
        With Worksheets("BDATOS")
            Cells(t + 1, 2) = TextBox6 & " " & TextBox7 & ", " & TextBox5
            Cells(t + 1, 3) = ComboBox5
            Cells(t + 1, 4) = ComboBox5 '
            Cells(t + 1, 5) = combobox1 '
            Cells(t + 1, 6) = ComboBox2
            Cells(t + 1, 7) = TextBox1.Value
            Cells(t + 1, 8) = TextBox2.Value
            Cells(t + 1, 9) = ComboBox3
            Cells(t + 1, 10) = ComboBox4
            Cells(t + 1, 11) = 0 + TextBox3
            Cells(t + 1, 12) = TextBox4.Value
            Cells(t + 1, 13) = CmbSexo
            Cells(t + 1, 14) = Right(TextBox1.Value, 4)
        End With
        Cells(t, 13).Select
        Selection.AutoFill Destination:=Range("M" & t & ":M" & t + 1), Type:=xlFillDefault
        Sheets("BDATOS").Protect ("acuario3511")
        For n = 1 To 12
            On Error Resume Next
            Controls("textbox" & n) = ""
            Controls("combobox" & n) = ""
        Next
        Sheets("DATOS").Select
        Cells.Select
        Cells.EntireColumn.AutoFit
    
End Sub
 
Upvote 0
SLIGHT ADJUSTMENT NOW

TRY THE BELOW



VBA Code:
Private Sub cmdbRegistrar_Click()
    Dim Salir As Boolean
    Dim fe1 As Date
    Dim fe2 As Date

If combobox1 = "SPAIN" And combobox1 = "PORTUGAL" Then
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Or TextBox6 = Empty Or TextBox7 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
Else
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
End If

        fe1 = CDate(TextBox1)
        TextBox1 = Format(fe1, "mm/dd/yyyy")
        If Not IsDate(TextBox2) Then
            MsgBox "INGRESE UNA FECHA VÁLIDA", vbExclamation
            TextBox2.SetFocus
            Exit Sub
        End If
        fe2 = CDate(TextBox2)
        TextBox2 = Format(fe2, "mm/dd/yyyy")
        Sheets("BDATOS").Select
        Sheets("BDATOS").Unprotect ("123")
        With Worksheets("BDATOS")
            Cells(t + 1, 2) = TextBox6 & " " & TextBox7 & ", " & TextBox5
            Cells(t + 1, 3) = ComboBox5
            Cells(t + 1, 4) = ComboBox5 '
            Cells(t + 1, 5) = combobox1 '
            Cells(t + 1, 6) = ComboBox2
            Cells(t + 1, 7) = TextBox1.Value
            Cells(t + 1, 8) = TextBox2.Value
            Cells(t + 1, 9) = ComboBox3
            Cells(t + 1, 10) = ComboBox4
            Cells(t + 1, 11) = 0 + TextBox3
            Cells(t + 1, 12) = TextBox4.Value
            Cells(t + 1, 13) = CmbSexo
            Cells(t + 1, 14) = Right(TextBox1.Value, 4)
        End With
        Cells(t, 13).Select
        Selection.AutoFill Destination:=Range("M" & t & ":M" & t + 1), Type:=xlFillDefault
        Sheets("BDATOS").Protect ("acuario3511")
        For n = 1 To 12
            On Error Resume Next
            Controls("textbox" & n) = ""
            Controls("combobox" & n) = ""
        Next
        Sheets("DATOS").Select
        Cells.Select
        Cells.EntireColumn.AutoFit
    
End Sub
 
Upvote 0
end if, ok the i did spot an error based on that.

try the below, im going to test it properly


VBA Code:
Private Sub cmdbRegistrar_Click()
    Dim Salir As Boolean
    Dim fe1 As Date
    Dim fe2 As Date

If combobox1 = "SPAIN" Or combobox1 = "PORTUGAL" Then
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Or TextBox6 = Empty Or TextBox7 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
Else
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
End If

        fe1 = CDate(TextBox1)
        TextBox1 = Format(fe1, "mm/dd/yyyy")
        If Not IsDate(TextBox2) Then
            MsgBox "INGRESE UNA FECHA VÁLIDA", vbExclamation
            TextBox2.SetFocus
            Exit Sub
        End If
        fe2 = CDate(TextBox2)
        TextBox2 = Format(fe2, "mm/dd/yyyy")
        Sheets("BDATOS").Select
        Sheets("BDATOS").Unprotect ("123")
        With Worksheets("BDATOS")
            Cells(t + 1, 2) = TextBox6 & " " & TextBox7 & ", " & TextBox5
            Cells(t + 1, 3) = ComboBox5
            Cells(t + 1, 4) = ComboBox5 '
            Cells(t + 1, 5) = combobox1 '
            Cells(t + 1, 6) = ComboBox2
            Cells(t + 1, 7) = TextBox1.Value
            Cells(t + 1, 8) = TextBox2.Value
            Cells(t + 1, 9) = ComboBox3
            Cells(t + 1, 10) = ComboBox4
            Cells(t + 1, 11) = 0 + TextBox3
            Cells(t + 1, 12) = TextBox4.Value
            Cells(t + 1, 13) = CmbSexo
            Cells(t + 1, 14) = Right(TextBox1.Value, 4)
        End With
        Cells(t, 13).Select
        Selection.AutoFill Destination:=Range("M" & t & ":M" & t + 1), Type:=xlFillDefault
        Sheets("BDATOS").Protect ("acuario3511")
        For n = 1 To 12
            On Error Resume Next
            Controls("textbox" & n) = ""
            Controls("combobox" & n) = ""
        Next
        Sheets("DATOS").Select
        Cells.Select
        Cells.EntireColumn.AutoFit
   
End Sub
Although I fill in all the controls except the 2 that remain disabled, when I select in the ComboBox1 elements other than SPAIN or PORTUGAL, it tells me that "MISSING DATA TO BE FILLED IN !!!".
 
Upvote 0
did you try post 13, you may have missed that
 
Upvote 0
OK

This one must work

VBA Code:
Private Sub cmdbRegistrar_Click()
    Dim Salir As Boolean
    Dim fe1 As Date
    Dim fe2 As Date

If combobox1 <> "SPAIN" And combobox1 <> "PORTUGAL" Then
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
Else
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Or TextBox6 = Empty Or TextBox7 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
End If

        fe1 = CDate(TextBox1)
        TextBox1 = Format(fe1, "mm/dd/yyyy")
        If Not IsDate(TextBox2) Then
            MsgBox "INGRESE UNA FECHA VÁLIDA", vbExclamation
            TextBox2.SetFocus
            Exit Sub
        End If
        fe2 = CDate(TextBox2)
        TextBox2 = Format(fe2, "mm/dd/yyyy")
        Sheets("BDATOS").Select
        Sheets("BDATOS").Unprotect ("123")
        With Worksheets("BDATOS")
            Cells(t + 1, 2) = TextBox6 & " " & TextBox7 & ", " & TextBox5
            Cells(t + 1, 3) = ComboBox5
            Cells(t + 1, 4) = ComboBox5 '
            Cells(t + 1, 5) = combobox1 '
            Cells(t + 1, 6) = ComboBox2
            Cells(t + 1, 7) = TextBox1.Value
            Cells(t + 1, 8) = TextBox2.Value
            Cells(t + 1, 9) = ComboBox3
            Cells(t + 1, 10) = ComboBox4
            Cells(t + 1, 11) = 0 + TextBox3
            Cells(t + 1, 12) = TextBox4.Value
            Cells(t + 1, 13) = CmbSexo
            Cells(t + 1, 14) = Right(TextBox1.Value, 4)
        End With
        Cells(t, 13).Select
        Selection.AutoFill Destination:=Range("M" & t & ":M" & t + 1), Type:=xlFillDefault
        Sheets("BDATOS").Protect ("acuario3511")
        For n = 1 To 12
            On Error Resume Next
            Controls("textbox" & n) = ""
            Controls("combobox" & n) = ""
        Next
        Sheets("DATOS").Select
        Cells.Select
        Cells.EntireColumn.AutoFit
   
End Sub
 
Upvote 0
OK

This one must work

VBA Code:
Private Sub cmdbRegistrar_Click()
    Dim Salir As Boolean
    Dim fe1 As Date
    Dim fe2 As Date

If combobox1 <> "SPAIN" And combobox1 <> "PORTUGAL" Then
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
Else
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Or TextBox6 = Empty Or TextBox7 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
End If

        fe1 = CDate(TextBox1)
        TextBox1 = Format(fe1, "mm/dd/yyyy")
        If Not IsDate(TextBox2) Then
            MsgBox "INGRESE UNA FECHA VÁLIDA", vbExclamation
            TextBox2.SetFocus
            Exit Sub
        End If
        fe2 = CDate(TextBox2)
        TextBox2 = Format(fe2, "mm/dd/yyyy")
        Sheets("BDATOS").Select
        Sheets("BDATOS").Unprotect ("123")
        With Worksheets("BDATOS")
            Cells(t + 1, 2) = TextBox6 & " " & TextBox7 & ", " & TextBox5
            Cells(t + 1, 3) = ComboBox5
            Cells(t + 1, 4) = ComboBox5 '
            Cells(t + 1, 5) = combobox1 '
            Cells(t + 1, 6) = ComboBox2
            Cells(t + 1, 7) = TextBox1.Value
            Cells(t + 1, 8) = TextBox2.Value
            Cells(t + 1, 9) = ComboBox3
            Cells(t + 1, 10) = ComboBox4
            Cells(t + 1, 11) = 0 + TextBox3
            Cells(t + 1, 12) = TextBox4.Value
            Cells(t + 1, 13) = CmbSexo
            Cells(t + 1, 14) = Right(TextBox1.Value, 4)
        End With
        Cells(t, 13).Select
        Selection.AutoFill Destination:=Range("M" & t & ":M" & t + 1), Type:=xlFillDefault
        Sheets("BDATOS").Protect ("acuario3511")
        For n = 1 To 12
            On Error Resume Next
            Controls("textbox" & n) = ""
            Controls("combobox" & n) = ""
        Next
        Sheets("DATOS").Select
        Cells.Select
        Cells.EntireColumn.AutoFit
  
End Sub
Nothing, it remains the same
 
Upvote 0
oh

ok, sorry, you know what, i missed something from your original post.

you said (ComboBox6 and TextBox7)

i have been removing the wrong ones.

TextBox6 and TextBox7

sorry, try the below

VBA Code:
Private Sub cmdbRegistrar_Click()
    Dim Salir As Boolean
    Dim fe1 As Date
    Dim fe2 As Date

If combobox1 <> "SPAIN" And combobox1 <> "PORTUGAL" Then
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Or TextBox6 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
Else
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Or TextBox6 = Empty Or TextBox7 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
End If

        fe1 = CDate(TextBox1)
        TextBox1 = Format(fe1, "mm/dd/yyyy")
        If Not IsDate(TextBox2) Then
            MsgBox "INGRESE UNA FECHA VÁLIDA", vbExclamation
            TextBox2.SetFocus
            Exit Sub
        End If
        fe2 = CDate(TextBox2)
        TextBox2 = Format(fe2, "mm/dd/yyyy")
        Sheets("BDATOS").Select
        Sheets("BDATOS").Unprotect ("123")
        With Worksheets("BDATOS")
            Cells(t + 1, 2) = TextBox6 & " " & TextBox7 & ", " & TextBox5
            Cells(t + 1, 3) = ComboBox5
            Cells(t + 1, 4) = ComboBox5 '
            Cells(t + 1, 5) = combobox1 '
            Cells(t + 1, 6) = ComboBox2
            Cells(t + 1, 7) = TextBox1.Value
            Cells(t + 1, 8) = TextBox2.Value
            Cells(t + 1, 9) = ComboBox3
            Cells(t + 1, 10) = ComboBox4
            Cells(t + 1, 11) = 0 + TextBox3
            Cells(t + 1, 12) = TextBox4.Value
            Cells(t + 1, 13) = CmbSexo
            Cells(t + 1, 14) = Right(TextBox1.Value, 4)
        End With
        Cells(t, 13).Select
        Selection.AutoFill Destination:=Range("M" & t & ":M" & t + 1), Type:=xlFillDefault
        Sheets("BDATOS").Protect ("acuario3511")
        For n = 1 To 12
            On Error Resume Next
            Controls("textbox" & n) = ""
            Controls("combobox" & n) = ""
        Next
        Sheets("DATOS").Select
        Cells.Select
        Cells.EntireColumn.AutoFit
   
End Sub
 
Upvote 0
That line was not part of my solution

Include an Exit Sub statement & update your line in RED as shown below & see if helps

Rich (BB code):
 If NotComplete Then
        MsgBox "MISSING DATA To BE FILLED IN !!!", vbExclamation, "Entry Required"
    Exit Sub
    End If

       If IsDate(TextBox1) Then fe1 = CDate(TextBox1)

Dave
 
Upvote 0
oh

ok, sorry, you know what, i missed something from your original post.

you said (ComboBox6 and TextBox7)

i have been removing the wrong ones.

TextBox6 and TextBox7

sorry, try the below

VBA Code:
Private Sub cmdbRegistrar_Click()
    Dim Salir As Boolean
    Dim fe1 As Date
    Dim fe2 As Date

If combobox1 <> "SPAIN" And combobox1 <> "PORTUGAL" Then
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Or TextBox6 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
Else
    If combobox1 = Empty Or ComboBox2 = Empty Or ComboBox3 = Empty Or ComboBox4 = Empty Or ComboBox5 = Empty Or _
    ComboBox6 = Empty Or TextBox1 = Empty Or TextBox2 = Empty Or TextBox3 = Empty Or TextBox4 = Empty Or _
    TextBox5 = Empty Or TextBox6 = Empty Or TextBox7 = Empty Then MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation: Exit Sub
End If

        fe1 = CDate(TextBox1)
        TextBox1 = Format(fe1, "mm/dd/yyyy")
        If Not IsDate(TextBox2) Then
            MsgBox "INGRESE UNA FECHA VÁLIDA", vbExclamation
            TextBox2.SetFocus
            Exit Sub
        End If
        fe2 = CDate(TextBox2)
        TextBox2 = Format(fe2, "mm/dd/yyyy")
        Sheets("BDATOS").Select
        Sheets("BDATOS").Unprotect ("123")
        With Worksheets("BDATOS")
            Cells(t + 1, 2) = TextBox6 & " " & TextBox7 & ", " & TextBox5
            Cells(t + 1, 3) = ComboBox5
            Cells(t + 1, 4) = ComboBox5 '
            Cells(t + 1, 5) = combobox1 '
            Cells(t + 1, 6) = ComboBox2
            Cells(t + 1, 7) = TextBox1.Value
            Cells(t + 1, 8) = TextBox2.Value
            Cells(t + 1, 9) = ComboBox3
            Cells(t + 1, 10) = ComboBox4
            Cells(t + 1, 11) = 0 + TextBox3
            Cells(t + 1, 12) = TextBox4.Value
            Cells(t + 1, 13) = CmbSexo
            Cells(t + 1, 14) = Right(TextBox1.Value, 4)
        End With
        Cells(t, 13).Select
        Selection.AutoFill Destination:=Range("M" & t & ":M" & t + 1), Type:=xlFillDefault
        Sheets("BDATOS").Protect ("acuario3511")
        For n = 1 To 12
            On Error Resume Next
            Controls("textbox" & n) = ""
            Controls("combobox" & n) = ""
        Next
        Sheets("DATOS").Select
        Cells.Select
        Cells.EntireColumn.AutoFit
  
End Sub
Finally, perfect
Thank you for your work and effort in solving this problem.
 
Upvote 0

Forum statistics

Threads
1,213,544
Messages
6,114,249
Members
448,556
Latest member
peterhess2002

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