Macro con evento en hojas protegidas

Para Dante Amor,

Tengo una macro con un evento en la pestaña “General” que copia datos a otras hojas según el valor de unas celdas en concreto. Lo que ocurre, es que si bloqueo algunas columnas y protejo la hoja, el evento da error y no se ejecuta.

A este libro acceden más personas que yo, entonces sería susceptible a que alguien borre por error alguna formula.

¿Sabes cómo se puede ejecutar el evento en hojas protegidas?

Muchas gracias de antemano, Dante!

Edgar@Copiar filas a otra hoja según valor celda

1 Respuesta

Respuesta
1

H o      l a :

Envíame un correo nuevo con el archivo con la macro y con la hoja protegida.

Enviado a tu email!

Anexo la macro actualizada para funcionar con hojas protegidas

Private Sub Worksheet_Change(ByVal Target As Range)
'Por.Dante Amor
    Set h1 = ActiveSheet
    Set h2 = Sheets("TTE+MTJ")
    Set h3 = Sheets("TTE")
    Set h4 = Sheets("Sin Servicios")
    '
    If Not Intersect(Target, Columns("CW")) Is Nothing Then
        '
        fila = Target.Row
        If Target.Count > 1 Then Exit Sub
        If fila < 16 Then Exit Sub
        If Cells(fila, "H") = "" Then Exit Sub
        If Cells(fila, "H") = "TOTALES" Then Exit Sub
        If Target.Value = "" Then Exit Sub
        If h1.Cells(fila, "EY") = 1 Then Exit Sub
        '
        Application.ScreenUpdating = False
        h1.Unprotect "qwer"
        h2.Unprotect "qwer"
        h3.Unprotect "qwer"
        h4.Unprotect "qwer"
        'copia a TTE
        If Cells(fila, "AI") <> "" And Cells(fila, "BF") = "" Then
            u = 16
            Do While h3.Cells(u, "H") <> ""
                u = u + 1
            Loop
            h1.Range("A" & Target.Row & ":DT" & fila).Copy h3.Range("A" & u)
            h1.Cells(fila, "EY") = 1
        End If
        'copia a TTE+MTJ
        If Cells(fila, "AI") <> "" And Cells(fila, "BF") <> "" Then
            u = 16
            Do While h2.Cells(u, "H") <> ""
                u = u + 1
            Loop
            h1.Range("A" & Target.Row & ":EX" & fila).Copy h2.Range("A" & u)
            h1.Cells(fila, "EY") = 1
        End If
        'copia a SinServicios
        If Cells(fila, "AI") = "" And Cells(fila, "BF") = "" Then
            u = 16
            Do While h4.Cells(u, "H") <> ""
                u = u + 1
            Loop
            h1.Range("A" & Target.Row & ":DT" & fila).Copy h4.Range("A" & u)
            h1.Cells(fila, "EY") = 1
        End If
        h1.Protect "qwer", DrawingObjects:=True, Contents:=True, _
            Scenarios:=True, AllowFormattingCells:=True
        h2.Protect "qwer", DrawingObjects:=True, Contents:=True, _
            Scenarios:=True, AllowFormattingCells:=True
        h3.Protect "qwer", DrawingObjects:=True, Contents:=True, _
            Scenarios:=True, AllowFormattingCells:=True
        h4.Protect "qwer", DrawingObjects:=True, Contents:=True, _
            Scenarios:=True, AllowFormattingCells:=True
        Application.ScreenUpdating = True
    End If
End Sub

sal u dos, r ecuerda cambiar la valoración a la respuesta.

La verdad es que funciona a la perfección. Tengo una cuestión más en el siguiente enlace.

Macron de eventos que revise si el dato evaluable se ha modificado 

De nuevo, mil gracias! Super resolutivo y rápido!

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas