Error 9 de ejecución en VBA con formulario

A la hora de hacer click en el formulario para ingresar la información en una hoja, me tira el error 9 de ejecución subíndice fuera del intervalo.

La hoja se protege cuando se guarda, pero le puse un código que cuando se vaya a ingresar la información desprotega la hoja y después ingrese los datos, pero me da error, revise y las hojas están bien escritas y si existen, si me pudieran ayudar. Adjunto el código.

Private Sub CommandButton1_Click()

Sheets("Detalle_salidas").Unprotect "2019"
If colaborador.Value = "" And servicio.Value = "" And empresa = "" And puesto = "" And cliente = "" And region = "" And motivo = "" Then
MsgBox "Debe llenar todos los espacios", vbInformation + vbOKOnly
colaborador.SetFocus
Exit Sub

Else

Application.ScreenUpdating = False

Sheets("Detalle_salidas").Select

Range("A" & Cells.Rows.Count).End(xlUp).Offset(1).Select

ActiveCell = colaborador.Value
ActiveCell.Offset(0, 1) = servicio.Value
ActiveCell.Offset(0, 2) = empresa.Value
ActiveCell.Offset(0, 3) = puesto.Value
ActiveCell.Offset(0, 4) = cliente.Value
ActiveCell.Offset(0, 5) = region.Value
ActiveCell.Offset(0, 6) = Format(fecha.Value, "mm/dd/yyyy")
ActiveCell.Offset(0, 7) = motivo.Value
If CheckBox1 = True Then
ActiveCell.Offset(0, 8) = "Sí"
End If
If CheckBox1 = False Then
ActiveCell.Offset(0, 8) = "No"
End If
colaborador = Empty
servicio = Empty
empresa = Empty
puesto = Empty
cliente = Empty
region = Empty
fecha = Empty
motivo = Empty
CheckBox1 = Empty
CheckBox2 = Empty
ActiveWorkbook.Save
colaborador.SetFocus

End If

Sheets("INICIO").Select

Application.ScreenUpdating = True

End Sub

El error me lo marca en la línea con negrita arriba del código.

1 Respuesta

Respuesta
1
Private Sub CommandButton1_Click()
Sheets("Detalle_salidas").Unprotect ("2019")
If colaborador.Value = "" And servicio.Value = "" And empresa = "" And puesto = "" And cliente = "" And region = "" And motivo = "" Then
MsgBox "Debe llenar todos los espacios", vbInformation + vbOKOnly
colaborador.SetFocus
Exit Sub
Else
Application.ScreenUpdating = False
Sheets("Detalle_salidas").Select
Range("A" & Cells.Rows.Count).End(xlUp).Offset(1).Select
ActiveCell = colaborador.Value
ActiveCell.Offset(0, 1) = servicio.Value
ActiveCell.Offset(0, 2) = empresa.Value
ActiveCell.Offset(0, 3) = puesto.Value
ActiveCell.Offset(0, 4) = cliente.Value
ActiveCell.Offset(0, 5) = region.Value
ActiveCell.Offset(0, 6) = Format(fecha.Value, "mm/dd/yyyy")
ActiveCell.Offset(0, 7) = motivo.Value
If CheckBox1 = True Then
ActiveCell.Offset(0, 8) = "Sí"
End If
If CheckBox1 = False Then
ActiveCell.Offset(0, 8) = "No"
End If
colaborador = Empty
servicio = Empty
empresa = Empty
puesto = Empty
cliente = Empty
region = Empty
fecha = Empty
motivo = Empty
CheckBox1 = Empty
CheckBox2 = Empty
ActiveWorkbook.Save
colaborador.SetFocus
End If
Sheets("INICIO").Select
Application.ScreenUpdating = True
Sheets("Detalle_salidas").Protect ("2019")
End Sub

Prueba así a ver si funciona.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas