ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Unprotect only certain cells after macros runs to unhide range of (https://www.excelbanter.com/excel-programming/367103-unprotect-only-certain-cells-after-macros-runs-unhide-range.html)

MiComputerGeek78

Unprotect only certain cells after macros runs to unhide range of
 
I have the following code which of course based on a checkboxthe person
selects unprotects the worksheet, unhides the specified range of rows and
then reprotects the workbook. As well if they un-check that checkbox it
will rehide those rows. I am creating this for a group of employees.

Here is my code:
------------------------------------------------------
Private Sub CheckBox1_Click()
'More then 1000 pr year
If CheckBox1 = True Then
Worksheets("Estimate").Unprotect "ds789"
Range(Rows(118), Rows(142)).EntireRow.Hidden = False
ElseIf CheckBox1 = False Then
Range(Rows(68), Rows(142)).EntireRow.Hidden = True
Worksheets("Estimate").Protect "ds789"
End If
End Sub

Private Sub CheckBox2_Click()
'For Lots 25 to 1000 pr year
If CheckBox2 = True Then
Worksheets("Estimate").Unprotect "ds789"
Range(Rows(92), Rows(117)).EntireRow.Hidden = False
ElseIf CheckBox2 = False Then
Range(Rows(68), Rows(141)).EntireRow.Hidden = True
Worksheets("Estimate").Protect "ds789"
End If
End Sub

Private Sub CheckBox3_Click()
'For Lots 1 to 25 pr year
If CheckBox3 = True Then
Worksheets("Estimate").Unprotect "ds789"
Range(Rows(66), Rows(92)).EntireRow.Hidden = False
ElseIf CheckBox3 = False Then
Range(Rows(68), Rows(141)).EntireRow.Hidden = True
Worksheets("Estimate").Protect "ds789"
End If

End Sub
--------------------------------------------------

So now what I need to do is specify in there to only allow certain cells in
those rows to be filled in. For example if they check checkbox1 then I need
to unhide the rows specified but then only allow entry in the range c71:c77.
I am thinking there has to be a way to do but I only know certain areas of
visual basic programming code and its been as I go I learn. I would greatly
appreciate anyone's assistance with this.
~M

Charlie

Unprotect only certain cells after macros runs to unhide range of
 
I think you have to unprotect the sheet, unlock the range of cells desired

Range().Locked = False

and reprotect the sheet. (Then vice-versa to relock the cells.)

"MiComputerGeek78" wrote:

I have the following code which of course based on a checkboxthe person
selects unprotects the worksheet, unhides the specified range of rows and
then reprotects the workbook. As well if they un-check that checkbox it
will rehide those rows. I am creating this for a group of employees.

Here is my code:
------------------------------------------------------
Private Sub CheckBox1_Click()
'More then 1000 pr year
If CheckBox1 = True Then
Worksheets("Estimate").Unprotect "ds789"
Range(Rows(118), Rows(142)).EntireRow.Hidden = False
ElseIf CheckBox1 = False Then
Range(Rows(68), Rows(142)).EntireRow.Hidden = True
Worksheets("Estimate").Protect "ds789"
End If
End Sub

Private Sub CheckBox2_Click()
'For Lots 25 to 1000 pr year
If CheckBox2 = True Then
Worksheets("Estimate").Unprotect "ds789"
Range(Rows(92), Rows(117)).EntireRow.Hidden = False
ElseIf CheckBox2 = False Then
Range(Rows(68), Rows(141)).EntireRow.Hidden = True
Worksheets("Estimate").Protect "ds789"
End If
End Sub

Private Sub CheckBox3_Click()
'For Lots 1 to 25 pr year
If CheckBox3 = True Then
Worksheets("Estimate").Unprotect "ds789"
Range(Rows(66), Rows(92)).EntireRow.Hidden = False
ElseIf CheckBox3 = False Then
Range(Rows(68), Rows(141)).EntireRow.Hidden = True
Worksheets("Estimate").Protect "ds789"
End If

End Sub
--------------------------------------------------

So now what I need to do is specify in there to only allow certain cells in
those rows to be filled in. For example if they check checkbox1 then I need
to unhide the rows specified but then only allow entry in the range c71:c77.
I am thinking there has to be a way to do but I only know certain areas of
visual basic programming code and its been as I go I learn. I would greatly
appreciate anyone's assistance with this.
~M



All times are GMT +1. The time now is 02:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com