Hola @RubenDario
Faltaría que en cada línea dentro del With le pongas un punto al inicio
With Hoja1
.Range("B6:B18,F6:F18,J6:J18").Select
.Range("J6").Activate
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
.Selection.ClearContents
.Range("A1").Select
End With
Sin embargo, lo que yo haría (si fuese mi proyecto)... te ofrezco varias soluciones.
No asignarlo a una combinación de teclas, mejor ponerlo en una forma o botón.
Modificar tu libro con la app Custom UI Editor o similar y adicionar un botón en el Ribbon, estará visible solo cuando el libro esté activo.
Al principio de tu código pondría algo como: If Thisworkbook.Name <> ActiveWorkbook.Name Then Exit sub
Por
DiegoPC, · publicado
Hola amig@s
Tengo un problema que no doy con el.
En el códigos siguiente, el Setfocus no “funciona”…
¿Qué estoy haciendo mal?...
De repente estoy trancado en alguna tontería pero ya “no veo” ja!.
Me podrias ayudar?
Gracias de antemano.
Private Sub cmdAceptar_click()
Application.ScreenUpdating = False
If Trim(Me.txt_fecha) = Empty Then
Me.txt_fecha.BackColor = &HC0C0FF
MsgBox "Debe ingresar la fecha de la operación", , "CAMPO VACIO"
Me.txt_fecha.SetFocus
Me.txt_fecha.SelStart = 0
Exit Sub
ElseIf Trim(Me.txt_Descripcion) = "" Then
Me.txt_Descripcion.BackColor = &HC0C0FF
MsgBox "Detalle la operacion", , "CAMPO VACIO"
Me.txt_Descripcion.SetFocus
Me.txt_Descripcion.SelStart = 0
Exit Sub
ElseIf me.cbx_Naturaleza = "" Then
Me.cbx_Naturaleza.BackColor = &HC0C0FF
MsgBox "Seleccione Naturaleza de la operación", , "CAMPO VACIO"
Me.cbx_Naturaleza.SetFocus
Me.cbx_Naturaleza.SelStart = 0
Exit Sub
ElseIf Me.cbx_Operacion = "" Then
Me.cbx_Operacion.BackColor = &HC0C0FF
MsgBox "Seleccione tipo de Operacion", , "CAMPO VACIO"
Me.cbx_Operacion.SetFocus
Me.cbx_Operacion.SelStart = 0
Exit Sub
ElseIf Me.cbx_Fondo = "" Then
Me.cbx_Fondo.BackColor = &HC0C0FF
MsgBox "Seleccione Fondo afectado", , "CAMPO VACIO"
Me.cbx_Fondo.SetFocus
Me.cbx_Fondo.SelStart = 0
Exit Sub
ElseIf Me.txt_Importe = "" Then
Me.txt_Importe.BackColor = &HC0C0FF
MsgBox "Ingrese el Importe", , "CAMPO VACIO"
Me.txt_Importe.SetFocus
Me.txt_Importe.SelStart = 0
Exit Sub
ElseIf Not IsDate(Me.txt_fecha.Value) Then 'verifica que sea una fecha valida
Me.txt_fecha.BackColor = &HC0C0FF
MsgBox "Fecha invalida.", vbCritical, " ERROR !"
Me.txt_fecha.SetFocus
Me.txt_fecha.SelStart = 0
Exit Sub
ElseIf Me.cbx_Naturaleza.Text = "Egresos" And Me.txt_Importe.Value > 0 Then
Me.txt_Importe.BackColor = &HC0C0FF
MsgBox "Debe ser importe negativo", vbCritical, " ERROR !"
Me.txt_Importe.SetFocus
Me.txt_Importe.SelStart = 0
Exit Sub
ElseIf Me.cbx_Naturaleza.Text = "Ingresos" And Me.txt_Importe.Value < 0 Then
Me.txt_Importe.BackColor = &HC0C0FF
MsgBox "Debe ser importe positivo", vbCritical, " ERROR !"
Me.txt_Importe.SetFocus
Me.txt_Importe.SelStart = 0
Exit Sub
End If