Simplemountain
New Member
- Joined
- Feb 26, 2016
- Messages
- 27
Hello,
I have a sheet I've been working on for some time that is a work sheet for pricing quotes.
I lock all the cells on the sheet except the ones needed to input data to keep all of my formulas safe. I added a clear Sheet button using code I got from this forum so that users could easily clear the sheet without affecting locked cells. Here is the code:
Sub ClearUnlockedCells()
Dim wks As Worksheet
For Each wks In ThisWorkbook.Field
On Error Resume Next
wks.UsedRange.Value = vbNullString
Err.Clear: On Error GoTo -1: On Error GoTo 0
Next wks
Set wks = Nothing
End Sub
This button works perfectly. I've realized now that I want to be able to allow users to change the value of certain cells for hourly rates. In order to keep my formulas intact, I created a second sheet in the Workbook where the rates can be entered and then set the applicable cells in the first sheet equal to them.
Now however, when I hit the clear sheet button, it clears the second sheet as well. Can someone advise on how I can change the code above to only clear the active sheet or some other solution? I've been experimenting but am missing something simple.
I have a sheet I've been working on for some time that is a work sheet for pricing quotes.
I lock all the cells on the sheet except the ones needed to input data to keep all of my formulas safe. I added a clear Sheet button using code I got from this forum so that users could easily clear the sheet without affecting locked cells. Here is the code:
Sub ClearUnlockedCells()
Dim wks As Worksheet
For Each wks In ThisWorkbook.Field
On Error Resume Next
wks.UsedRange.Value = vbNullString
Err.Clear: On Error GoTo -1: On Error GoTo 0
Next wks
Set wks = Nothing
End Sub
This button works perfectly. I've realized now that I want to be able to allow users to change the value of certain cells for hourly rates. In order to keep my formulas intact, I created a second sheet in the Workbook where the rates can be entered and then set the applicable cells in the first sheet equal to them.
Now however, when I hit the clear sheet button, it clears the second sheet as well. Can someone advise on how I can change the code above to only clear the active sheet or some other solution? I've been experimenting but am missing something simple.