Macro que funcione estando en cualquier hoja.
Para Dante Amor.
Ante todo un cordial saludo, tengo una macro que me diste lo cual funciona bien, solo que cuando lo ejecutó en una hoja diferente esta no trabaja, y esto pasa tanto para los botones de siguiente y anterior.
En este caso que le faltaria para que pueda trabajar y poder ejecutarla estando en cualquier hoja.
La macro que me diste es la siguiente.
Dim direccion
'
Private Sub CommandButton1_Click()
'Buscar
direccion = ""
Call Buscar(1, xlNext, "A1")
End Sub
Private Sub CommandButton2_Click()
'Siguiente
Call Buscar(2, xlNext, direccion)
End Sub
Private Sub CommandButton3_Click()
'Anterior
Call Buscar(2, xlPrevious, direccion)
End Sub
'
Sub Buscar(op, hacia, celda)
'Por.Dante Amor
TextBox2 = ""
If op = 2 And direccion = "" Then
MsgBox "Debes primero Buscar el código"
TextBox1.SetFocus
Exit Sub
End If
If TextBox1 = "" Then
MsgBox "Captura el código"
TextBox1.SetFocus
Exit Sub
End If
Set b = Columns("A").Find(TextBox1, After:=Range(celda), Lookat:=xlWhole, SearchDirection:=hacia)
If Not b Is Nothing Then
TextBox2 = b.Offset(0, 1)
direccion = b.Address
Else
MsgBox "El código no existe"
End If
End Sub
'
Private Sub TextBox1_Change()
TextBox2 = ""
direccion = ""
End Sub
1 Respuesta
Respuesta de La Buena Pera