Protecting cells

axj

New Member
Joined
Nov 30, 2005
Messages
21
Hey people, its me again :wink: . ive got another little problem. Ive assigned values to certain cells in vba. How do i protect these cells so they cannot be changed?

example of the code ive just used

Code:
Sub Locations()
      Range("J7").Value = "Germany"
      Range("Q7").Value = "Italy"
End Sub

how do i protect these cells using vba or should i just use the validate option in excels toolbar
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Maybe something like this:

<font face=tahoma><SPAN style="color:#00007F">Sub</SPAN> Locations()
      ActiveSheet.Unprotect
            <SPAN style="color:#00007F">With</SPAN> Range("J7")
                .Value = "Germany"
                .Locked = <SPAN style="color:#00007F">True</SPAN>
            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
            <SPAN style="color:#00007F">With</SPAN> Range("Q7")
                .Value = "Italy"
                .Locked = <SPAN style="color:#00007F">True</SPAN>
            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
        ActiveSheet.Protect
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope that helps,

Smitty
 

axj

New Member
Joined
Nov 30, 2005
Messages
21
it didnt seem to work, i think im just going to use the validation option in excels toolbar.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,798
Messages
5,833,741
Members
430,228
Latest member
Normano

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
Top