Macro Para actualizar Dato de un Textbox

Para: Dante

Tengo un formulario en la que ingreso datos con un textbox que jala el valor de una celda de cierta columna el inconveniente que tengo es que al guardar nuevos datos a la hoja; en el textbox de mi formulario debería actualizarse automáticamente el nuevo registro.

En la primera imagen se muestra como es en el inicio de formulario.

En la segunda se muestra de como debería de quedar cuando se guarda un nuevo dato.

El codigo del boton Guardar es el siguiente.

Private Sub CommandButton1_Click()
Set h1 = Sheets("Etiquetadora")
If ComboBox1 = "" Or ComboBox2 = "" Or ComboBox3 = "" Or ComboBox4 = "" _
Or TextBox2 = "" Or TextBox3 = "" Then
MsgBox "No son datos suficientes", vbInformation, ""
ComboBox2.SetFocus
Else
Application.ScreenUpdating = False
u = h1.Range("B" & Rows.Count).End(xlUp).Row + 1
        If u < 6 Then u = 6
h1.Cells(u, 2) = ComboBox1
h1.Cells(u, 3) = Format(Now, "hh:mm AM/PM")
h1.Cells(u, 4) = ComboBox2
h1.Cells(u, 6) = ComboBox4
h1.Cells(u, 7) = ComboBox3
h1.Cells(u, 8) = TextBox2
h1.Cells(u, 9) = TextBox3
ComboBox1 = Empty
ComboBox2 = Empty
ComboBox3 = Empty
ComboBox4 = Empty
TextBox2 = Empty
TextBox3 = Empty
ComboBox2.SetFocus
MsgBox "Fin de Registro", vbInformation
End If
End Sub

La macro que muestra el dato en el textbox de la celda Columna "I".

Private Sub Userform_Activate()
    Set h1 = Sheets("Etiquetadora")
    u = h1.Range("I" & Rows.Count).End(xlUp).Row
    TextBox2 = h1.Range("I" & u)
    ComboBox1 = Date
End Sub

2 respuestas

Respuesta
1
Private Sub CommandButton1_Click()
Set h1 = Sheets("Etiquetadora")
If ComboBox1 = "" Or ComboBox2 = "" Or ComboBox3 = "" Or ComboBox4 = "" _
Or TextBox2 = "" Or TextBox3 = "" Then
MsgBox "No son datos suficientes", vbInformation, ""
ComboBox2.SetFocus
Else
Application.ScreenUpdating = False
u = h1.Range("B" & Rows.Count).End(xlUp).Row + 1
        If u < 6 Then u = 6
h1.Cells(u, 2) = ComboBox1
h1.Cells(u, 3) = Format(Now, "hh:mm AM/PM")
h1.Cells(u, 4) = ComboBox2
h1.Cells(u, 6) = ComboBox4
h1.Cells(u, 7) = ComboBox3
h1.Cells(u, 8) = TextBox2
h1.Cells(u, 9) = TextBox3
     ' limpia form y prepara para el siguiente registro
     'ComboBox1 = Empty
     ComboBox1 = Date
ComboBox2 = Empty
ComboBox3 = Empty
ComboBox4 = Empty
     'TextBox2 = Empty
     TextBox2 = TextBox3   '<<< pone el numero que estaba en el t3 al t2
     'TextBox3 = Empty
ComboBox2.SetFocus
MsgBox "Fin de Registro", vbInformation
End If
End Sub
Respuesta
1

Te anexo la macro actualizada.

Después de registrar en la hoja, en el combo1 te pongo la fecha, en el textbox2 te pongo lo que tienes en el textbox3, también te puse esto:

h1.Cells(u, 2) = CDate(ComboBox1)

Para que te ponga en la celda una fecha, ya que te estaba poniendo la fecha como un texto.

Private Sub CommandButton1_Click()
    Set h1 = Sheets("Etiquetadora")
    If ComboBox1 = "" Or ComboBox2 = "" Or ComboBox3 = "" Or _
       ComboBox4 = "" Or TextBox2 = "" Or TextBox3 = "" Then
        MsgBox "No son datos suficientes", vbInformation, ""
        ComboBox2.SetFocus
    Else
        Application.ScreenUpdating = False
        u = h1.Range("B" & Rows.Count).End(xlUp).Row + 1
        If u < 6 Then u = 6
        '
        h1.Cells(u, 2) = CDate(ComboBox1)
        h1.Cells(u, 3) = Format(Now, "hh:mm AM/PM")
        h1.Cells(u, 4) = ComboBox2
        h1.Cells(u, 6) = ComboBox4
        h1.Cells(u, 7) = ComboBox3
        h1.Cells(u, 8) = TextBox2
        h1.Cells(u, 9) = TextBox3
        '
        ComboBox1 = Date
        ComboBox2 = Empty
        ComboBox3 = Empty
        ComboBox4 = Empty
        TextBox2 = TextBox3
        TextBox3 = Empty
        ComboBox2.SetFocus
        Application.ScreenUpdating = True
        MsgBox "Fin de Registro", vbInformation
    End If
End Sub

Saludos.Dante Amor

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas