Pasedo,
No botão para selecionar o próximo registro há uma situação na verificação do último registro que está causando esse comportamento. Para verificar se o registro atual é o último você mandou o Excel selecionar a próxima linha (ActiveCell.Offset(1,0).Select). Ao fazer isso, uma vez que o registro atual não é o último, você pulou um registro. Você não precisa selecionar a linha para verificar; pode fazer simplesmente If ActiveCell.Offset(1, 0) = "" Then. O mesmo ocorre na verificação do primeiro registro.
Seguem abaixo os dois códigos ajustados:
Código: Selecionar todos
Private Sub btn_proximo_Click()
Dim quantidade As Integer
Dim linha_atual As Integer
Dim ultima_linha As Integer
ultima_linha = (Sheets("Plan1").Range("A" & Rows.Count).End(xlUp).Row)
quantidade = (Sheets("Plan1").Range("A" & Rows.Count).End(xlUp).Row) - 1
linha_atual = ActiveCell.Row
If linha_atual < ultima_linha Then
Me.txt_Codigo = Sheets("Plan1").Range("A" & linha_atual + 1)
Sheets("Plan1").Range("A" & linha_atual + 1).Select
'Call txt_Codigo_AfterUpdate
End If
If ActiveCell.Offset(1, 0) = "" Then
Call txt_Codigo_AfterUpdate
MsgBox "Você está no último registro", vbInformation, "CADASTRO"
Else
Call txt_Codigo_AfterUpdate
End If
Me.txt_registro = ActiveCell.Row - 1 & "/" & quantidade
End Sub
Código: Selecionar todos
Private Sub btn_anterior_Click()
Dim quantidade As Integer
Dim linha_atual As Integer
Dim primeira_linha As Integer
primeira_linha = 2
quantidade = (Sheets("Plan1").Range("A" & Rows.Count).End(xlUp).Row) - 1
linha_atual = ActiveCell.Row
If linha_atual > primeira_linha Then
Me.txt_Codigo = Sheets("Plan1").Range("A" & linha_atual - 1)
Sheets("Plan1").Range("A" & linha_atual - 1).Select
'Call txt_Codigo_AfterUpdate
End If
If ActiveCell.Offset(-1, 0) = "CÓDIGO" Then
ActiveCell.Offset(1, 0).Select
Call txt_Codigo_AfterUpdate
MsgBox "Você está no primeiro registro", vbInformation, "CADASTRO"
Else
Call txt_Codigo_AfterUpdate
End If
Me.txt_registro = ActiveCell.Row - 1 & "/" & quantidade
End Sub