Botones primero,anterior,siguiente y ultimo registro en excel

Tengo cuatro botones para moverme por mis registro de una hoja excel.

Los botones primero y ultimo van perfectos. Los botones anterior y siguiente van bien pero con un matiz.

Cuando llego con el boton anterior al primer registro y le doy despues a siguiente me salta un resgitro (me pasa del registro 1 al 3) y con el boton siguiente cuando llego al ultimo registro y le doy despues al boton anterior me salta un resgitro (del 15 al 13).

Coloco el codigo de los 4 botones a ver si me puede ayudar. GRACIAS!

CODIGO

Public fila
Private Sub cmb_anterior_Click()
Cells(fila - 1, 1).Select
cbx_codigo.Value = ActiveCell
txt_nombre.Value = ActiveCell.Offset(0, 1)
cbx_plataforma.Value = ActiveCell.Offset(0, 2)
cbx_consola.Value = ActiveCell.Offset(0, 3)
cbx_categoria.Value = ActiveCell.Offset(0, 4)
cbx_grupo.Value = ActiveCell.Offset(0, 5)
cbx_estado.Value = ActiveCell.Offset(0, 6)
cbx_condicion.Value = ActiveCell.Offset(0, 7)
txt_ubicacion.Value = ActiveCell.Offset(0, 8)
txt_precio.Value = ActiveCell.Offset(0, 9)
txt_cantidad.Value = ActiveCell.Offset(0, 10)
If ActiveCell.Row = 2 Then
MsgBox "Estás en el primer artículo", vbInformation, "MIS JUEGOS"
Exit Sub
End If
fila = ActiveCell.Row
End Sub

Private Sub cmb_primero_Click()
cbx_codigo.Value = Range("A2").Value
txt_nombre.Value = Range("B2").Value
cbx_plataforma.Value = Range("C2").Value
cbx_consola.Value = Range("D2").Value
cbx_categoria.Value = Range("E2").Value
cbx_grupo.Value = Range("F2").Value
cbx_estado.Value = Range("G2").Value
cbx_condicion.Value = Range("H2").Value
txt_ubicacion.Value = Range("I2").Value
txt_precio.Value = Range("J2").Value
txt_cantidad.Value = Range("K2").Value
fila = 2
MsgBox "Estás en el primer artículo", vbInformation, "MIS JUEGOS"
End Sub

Private Sub cmb_siguiente_Click()
ultima = Range("a65000").End(xlUp).Row
Cells(fila + 1, 1).Select
cbx_codigo.Value = ActiveCell
txt_nombre.Value = ActiveCell.Offset(0, 1)
cbx_plataforma.Value = ActiveCell.Offset(0, 2)
cbx_consola.Value = ActiveCell.Offset(0, 3)
cbx_categoria.Value = ActiveCell.Offset(0, 4)
cbx_grupo.Value = ActiveCell.Offset(0, 5)
cbx_estado.Value = ActiveCell.Offset(0, 6)
cbx_condicion.Value = ActiveCell.Offset(0, 7)
txt_ubicacion.Value = ActiveCell.Offset(0, 8)
txt_precio.Value = ActiveCell.Offset(0, 9)
txt_cantidad.Value = ActiveCell.Offset(0, 10)

If ActiveCell.Row = ultima Then
MsgBox "Estás en el último artículo", vbInformation, "MIS JUEGOS"
Exit Sub
End If
fila = ActiveCell.Row
End Sub

Private Sub cmb_ultimo_Click()
ultima = Range("a65000").End(xlUp).Row
Cells(ultima, 1).Select
cbx_codigo.Value = ActiveCell
txt_nombre.Value = ActiveCell.Offset(0, 1)
cbx_plataforma.Value = ActiveCell.Offset(0, 2)
cbx_consola.Value = ActiveCell.Offset(0, 3)
cbx_categoria.Value = ActiveCell.Offset(0, 4)
cbx_grupo.Value = ActiveCell.Offset(0, 5)
cbx_estado.Value = ActiveCell.Offset(0, 6)
cbx_condicion.Value = ActiveCell.Offset(0, 7)
txt_ubicacion.Value = ActiveCell.Offset(0, 8)
txt_precio.Value = ActiveCell.Offset(0, 9)
txt_cantidad.Value = ActiveCell.Offset(0, 10)
fila = ActiveCell.Row
MsgBox "Estás en el último artículo", vbInformation, "MIS JUEGOS"
End Sub

1 respuesta

Respuesta
2

Te anexo un nuevo código, en el evento activate, selecciona la celda A2 para iniciar.

No es necesaria la variable fila como publica.

Creé un procedimiento para visualizar el registro, solamente recibe como parámetro la celda activa.

Sub Visualiza_Registro(fila)
'Por.Dante Amor
    cbx_codigo.Value = Cells(fila, "A").Value
    txt_nombre.Value = Cells(fila, "B").Value
    cbx_plataforma.Value = Cells(fila, "C").Value
    cbx_consola.Value = Cells(fila, "D").Value
    cbx_categoria.Value = Cells(fila, "E").Value
    cbx_grupo.Value = Cells(fila, "F").Value
    cbx_estado.Value = Cells(fila, "G").Value
    cbx_condicion.Value = Cells(fila, "H").Value
    txt_ubicacion.Value = Cells(fila, "I").Value
    txt_precio.Value = Cells(fila, "J").Value
    txt_cantidad.Value = Cells(fila, "K").Value
End Sub
Private Sub cmb_siguiente_Click()
    If Range("A" & Rows.Count).End(xlUp).Row = ActiveCell.Row Then
        MsgBox "Estás en el último artículo", vbInformation, "MIS JUEGOS"
    Else
        Cells(ActiveCell.Row + 1, "A").Select
        Call Visualiza_Registro(ActiveCell.Row)
    End If
End Sub
Private Sub cmb_primero_Click()
    Range("A2").Select
    Call Visualiza_Registro(ActiveCell.Row)
    MsgBox "Estás en el primer artículo", vbInformation, "MIS JUEGOS"
End Sub
Private Sub cmb_ultimo_Click()
    Range("A" & Range("A" & Rows.Count).End(xlUp).Row).Select
    Call Visualiza_Registro(ActiveCell.Row)
    MsgBox "Estás en el último artículo", vbInformation, "MIS JUEGOS"
End Sub
Private Sub cmb_anterior_Click()
    If ActiveCell.Row = 2 Then
        MsgBox "Estás en el primer artículo", vbInformation, "MIS JUEGOS"
    Else
        Cells(ActiveCell.Row - 1, "A").Select
        Call Visualiza_Registro(ActiveCell.Row)
    End If
End Sub
'
Private Sub UserForm_Activate()
    Range("A2").Select
End Sub

.

'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

.

Avísame cualquier duda

.

¡Gracias!

Buah! Funciona perfecto.

Muchísimas Gracias!

Ya iré preguntando más dudas, mientras vayan saliendo.!

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas