Como refrescar el textbox donde muestro el ultimo registro

Tengo un textbox que me muestra el ultimo registro, por ejemplo muestra el numero 6 y a eso le suma uno para guardar el siguiente registro pero cuando guardo toda la información me mantiene el mismo numero de registro y el la base de datos me aparece 7, como podría hacer para que se actualice ese numero automáticamente al guardar el registro sin tener que cerrar el form.

Respuesta
1

Te paso la macro

Sub Macro_copiar()
'
' Por Adriel Ortiz
    Set h1 = Sheets("Hoja1")
    Set h2 = Sheets("Hoja2")
    '
    u = h2.Range("A" & Rows.Count).End(xlUp).Row + 1
    If u < 2 Then u = 2
    h2.Cells(u, "A") = h1.[A4]
    h2.Cells(u, "B") = h1.[B7]
    h2.Cells(u, "C") = h1.[C7]
    h2.Cells(u, "D") = h1.[D7]
    '
    h1.Range("A4", "B7:D7").ClearContents
    MsgBox "fin"
End Sub

Adriel podrías darme cierta explicación que hace esa macros ?

Soy nuevo en el tema amigo.

Disculpa me equivoqué de usuario

Necesitas generar tu código automáticamente, ¿de ser así de cual columna tienes tu código?

Si tu código está en la columna A apartir de la fila 2

Usa esto

Private Sub UserForm_Activate()
    Set h = Sheets("Hoja1")
    '
    u = h.Range("A" & Rows.Count).End(xlUp).Row
    serie = Application.WorksheetFunction.Max(h.Range("A2:A" & u))
    TextBox1 = serie + 1
End Sub

valora la respuesta para finalizar

Adriel yo ya genero el ultimo numero:

Set h1 = Sheets("MATRIZ 1")
u = h1.Range("A" & Rows.Count).End(xlUp).Row
TextBox1 = h1.Range("A" & u) + 1

ese es mi código, en el form cuando abro en el textbox me sale 1, realizo el llenado de las demás textbox y guardo, pero al guardar se borra la información de todo y no se actualiza automáticamente textbox1 del numero 1 al 2 y así sucesivamente, mil disculpas por preguntarte tanto.

Sería así

Private Sub CommandButton1_Click()
'BOTON GUARDAR
Set h = Sheets("Hoja1")
    '
    u = h.Range("A" & Rows.Count).End(xlUp).Row + 1
    h.Cells(u, "A") = TextBox1
    h.Cells(u, "B") = TextBox2
    '
    'aqui el resto
    '
    MsgBox "Guardado con éxito"
End Sub
Private Sub UserForm_Activate()
    'CUANDO EJECUTAMOS EL FORMULARIO MUESTRA EL CODIGO +1
    Set h = Sheets("Hoja1")
    '
    u = h.Range("A" & Rows.Count).End(xlUp).Row
    serie = Application.WorksheetFunction.Max(h.Range("A2:A" & u))
    TextBox1 = serie + 1
End Sub

valora para finalizar saludos!

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas