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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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
 
Upvote 0
it didnt seem to work, i think im just going to use the validation option in excels toolbar.
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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