Macro que trabaje estando en cualquier hoja
Tengo un libro excel en la cual contiene varias hojas con diferentes nombres, cuando ejecutó la macro en la hoja especifica o en la hoja que guarda la información trabaja perfectamente, el problema viene cuando me voy a una hoja distinta esta ya no me trabaja me gustaría saber cual seria el problema porque este libro de excel que tengo tiene unos 50 hojas distintas.
Ante todo mil gracias por la respuesta que me puedan dar.
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 Dante Amor
1