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
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

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.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,534
Messages
5,572,743
Members
412,482
Latest member
arooshrana2
Top