muhleebbin
Active Member
- Joined
- Sep 30, 2017
- Messages
- 252
- Office Version
- 365
- 2019
- 2016
- 2013
- 2010
- Platform
- Windows
- MacOS
- Mobile
- Web
I have the following code where if you change a percentage value in cell K1 it will calculate the upcoming years rates. Is there a way to add a toggle button that would disable the code from filling in the calculated fields as well as lock the values in I3:I54 so that no further changes can be made?
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.CutCopyMode = False
Dim strFormulas(1 To 1) As Variant
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
If Not Intersect(Target, Range("K1")) Is Nothing Then
If ws.Range("K1") <> "" Then
With ThisWorkbook.Sheets("Sheet1")
.Range("I3:I54").ClearContents
strFormulas(1) = "=IFERROR(MROUND(H3+(H3*$K$1),5),"""")"
.Range("I3").Formula = strFormulas
.Range("I3").Copy
.Range("I3:I54").PasteSpecial Paste:=xlPasteFormulas
.Range("I3").Select
End With
Else
ws.Range("I3:I54").ClearContents
End If
End If
Application.ScreenUpdating = True
Application.CutCopyMode = True
End Sub