Need help with code

master_of_none

Board Regular
Joined
Jan 29, 2003
Messages
62
I need help putting another code in the same sub.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Set rng = Range("O2:O501")

If Intersect(Target, rng) Is Nothing Then Exit Sub

If Target.Value <> "X" Then
With Target
.Value = "X"
With .Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 14
.ColorIndex = 3
End With

Plus this one



Set rng = Range("P2:P501")

If Intersect(Target, rng) Is Nothing Then Exit Sub

If Target.Value <> "X" Then
With Target
.Value = "X"
With .Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 14
.ColorIndex = 5
End With
 
Last edited:
That should be BETWEEN

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Sheets("SheetName").Unprotect "PasswordHere"

rest of code here

Sheets("SheetName").Protect "PasswordHere"End Sub
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
That should be BETWEEN

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Sheets("SheetName").Unprotect "PasswordHere"

rest of code here

Sheets("SheetName").Protect "PasswordHere"End Sub

I get a run time error code 9

Subscript out of range
 
Upvote 0
Did you adjust SheetName to reflect the name of the sheet you're working with???
 
Upvote 0
Check spelling, look for extra spaces. In both the code, and the actual sheet tab.
 
Upvote 0
by using the code to unprotect the sheet, you won't have to worry about whether they're locked or not...

and when you reprotect the sheet at the end of the code, it will remember the settings that were there when you unprotected it..
 
Upvote 0
by using the code to unprotect the sheet, you won't have to worry about whether they're locked or not...

and when you reprotect the sheet at the end of the code, it will remember the settings that were there when you unprotected it..


When I protect the sheet the regular way, it prompt if you want to allow editing, select cell that are lock, select cell that are unlock ect. ect.

I have it set up not to select cells that are locked and the sheet is protected. When I use the code that you gave me, the cells are lock but you can still select them. Can I add anything else to the "Sheets("sheetname").protect " line to have the cells not be able to be selected?
 
Upvote 0
and when you reprotect the sheet at the end of the code, it will remember the settings that were there when you unprotected it..

It will remember the way it was set before..
 
Upvote 0
It will remember the way it was set before..


I tried it again. When I fire the code it works the correct way. I close the file and save changes and reopen it, you can select the cells that are locked and you cannot edit them.

I created a macro and view it.

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub


Can I use any of this?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top