Change locked cell

前端 未结 1 471
醉酒成梦
醉酒成梦 2021-01-25 04:04

I am using a VBA code to get sums but it does not work when cells are locked.

I want that no one can change the value of the specific cell manually but the VBA code can

相关标签:
1条回答
  • 2021-01-25 04:15

    maybe you can do it this way:

    Sub Get_Sum()
        Dim LastRow As Long
        Sheets("Sheetname").Unprotect Password:= "password"
        LastRow = Range("B5000").End(xlUp).Row
        Range("D" & LastRow + 1) = "Total Amount"
        Range("E" & LastRow + 1).Formula = "=SUM(E4:E" & LastRow & ")"
        Range("F" & LastRow + 1).Formula = "=SUM(F4:F" & LastRow & ")"
        Range("G" & LastRow + 1).Formula = "=SUM(G4:G" & LastRow & ")"
        Sheets("Sheetname").Protect Password:= "password"
    End Sub
    
    0 讨论(0)
提交回复
热议问题