Tengo protegida mi hoja y me sae un error cuando abre..

'Act. Por. Dante. Amor
'
lastrow = Sheets("MKP"). Cells(Rows. Count, "A").End(xlUp). Row
Sheets("MKP").Range("AE:AN").Locked = False
Tengo protegida mi hoja y aqui me sale un eror , cmo puedo solucionar esto
With Range("AE2:AI" & lastrow)
.Formula = "=sum(G2:G100)"
End With
'
With Range("AJ2:AN" & lastrow)
.Formula = "=sum(O2:O100)"
End With
'
Sheets("MKP").Range("AE:AN").Locked = True
'
'
UserForm1.Show
End Sub

2 Respuestas

Respuesta
1

Si tu hoja y/o las celdas en las que quieres hacer cambios a través de VBA están protegidas, para que no te arroje ningún error, debe desprotegerlas y protegerlas. Prueba algo así:

Worksheets("Nombre_de_tu_hoja").Unprotect Password:="tu_contraseña"
'Aquí todo lo que quieras hacer
Worksheets("Nombre_de_tu_hoja").Protect Password:="tu_contraseña"

Comentas

Abraham Valencia

Respuesta
1

Cambia "abc" por el password que tengas en tu hoja

'Act. Por. Dante. Amor
'
    pass = "abc"
    Sheets("MKP").Unprotect pass
    lastrow = Sheets("MKP").Cells(Rows.Count, "A").End(xlUp).Row
    'Sheets("MKP").Range("AE:AN").Locked = False
    With Range("AE2:AI" & lastrow)
        .Formula = "=sum(G2:G100)"
    End With
    '
    With Range("AJ2:AN" & lastrow)
        .Formula = "=sum(O2:O100)"
    End With
    '
    'Sheets("MKP").Range("AE:AN").Locked = True
    '
    '
    Sheets("MKP").Protect pass
    UserForm1.Show

.

'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas