Como lanzar userform al aceptar un msg box

Hola expertos hice este código que buscar el dato de la celdad p2 si no existe arroja un msg box lo que quiero es que al aceptar en el msg box lance un userfomr que ya tengo generado, para agregar el código en la "hoja datos" una ves agregado continué la ejecución de la macro, pero no logro realizarlo espero puedan ayudarme

Sub recorrer_filatucbook()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Range("p2").Select
ActiveCell.Formula = "20320" & Range("p3") & Range("U4") & Range("q3") & Range("V4") & Range("r3")
If Application.CountIf(Worksheets("datos").Range("A2:A500"), Worksheets("validar").Range("p2")) > 0 Then
Else
MsgBox ("código no existe")
End If
Range("A13").Select
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Formula = "20320" & Range("p3") & Range("U4") & Range("q3") & Range("V4") & Range("r3")
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

1 Respuesta

Respuesta
1

Probemos con el siguiente código.

Sub recorrer_filatucbook()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Range("p2").Select
ActiveCell.Formula = "20320" & Range("p3") & Range("U4") & Range("q3") & Range("V4") & Range("r3")
If Application.CountIf(Worksheets("datos").Range("A2:A500"), Worksheets("validar").Range("p2")) > 0 Then
Else
MsgBox ("código no existe",VbYesNo)

If respuesta = vbYes Then "lance un userfomr" Else Exit Sub

End If
Range("A13").Select
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Formula = "20320" & Range("p3") & Range("U4") & Range("q3") & Range("V4") & Range("r3")
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

En "lance un userfomr" deberías poner el nombre del UserForm

Atentamente.

Lucas.

<div id="wrc-float-icon" style="z-index: 2147483646; left: 15px; top: 15px; width: 42px; height: 42px; background-image: url('safari-extension://com.avast.wrc-6H4HRTU5E3/90c765b3/images/float/green-1.png'); position: fixed; display: none;"> </div>

Hola gracias por contestar al correr esta linea me arroja un error

........

Else
MsgBox ("código no existe",VbYesNo)

Error de compilación se esperaba =

Perdón no lo había probado y te indique algo mal.

Sub recorrer_filatucbook()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Range("p2").Select
ActiveCell.Formula = "20320" & Range("p3") & Range("U4") & Range("q3") & Range("V4") & Range("r3")
If Application.CountIf(Worksheets("datos").Range("A2:A500"), Worksheets("validar").Range("p2")) > 0 Then
Else
MsgBox ("código no existe",VbYesNo)
If respuesta = vbYes Then

"lance un userfomr".Show

Else

Exit Sub
End If
Range("A13").Select
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Formula = "20320" & Range("p3") & Range("U4") & Range("q3") & Range("V4") & Range("r3")
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Atentamente.

Lucas.

<div id="wrc-float-icon" style="z-index: 2147483646; left: 15px; top: 15px; width: 42px; height: 42px; background-image: url('safari-extension://com.avast.wrc-6H4HRTU5E3/30f3a6e2/images/float/green-1.png'); position: fixed; display: none;"> </div>

Igual que ves anterior

MsgBox ("código no existe",VbYesNo)
Error de compilación se esperaba =

cunado escribo esta linea me da error.

Veamos si asi funciona. De lo contrario y si el archivo no tiene información sensible se agradecería que me lo envíes a [email protected]

Sub recorrer_filatucbook()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Range("p2").Select
ActiveCell.Formula = "20320" & Range("p3") & Range("U4") & Range("q3") & Range("V4") & Range("r3")
If Application.CountIf(Worksheets("datos").Range("A2:A500"), Worksheets("validar").Range("p2")) > 0 Then
Else
RESPUESTA = MsgBox("código no existe", vbYesNo)
If RESPUESTA = vbYes Then
UserForm1.Show 'Aquí tienes que poner el nombre de tu UserForm
Else
Exit Sub
End If
Range("A13").Select
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Formula = "20320" & Range("p3") & Range("U4") & Range("q3") & Range("V4") & Range("r3")
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End If
End Sub

Atención: UserForm1.Show 'Aquí tienes que poner el nombre de tu UserForm

Atte.

Lucas.

<div id="wrc-float-icon" style="z-index: 2147483646; left: 15px; top: 15px; width: 42px; height: 42px; background-image: url('safari-extension://com.avast.wrc-6H4HRTU5E3/5aa8ecdd/images/float/green-1.png'); position: fixed; display: none;"> </div>

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas