Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make cells read-only in spreadsheets?

I'm populating a spreadsheet with Database values. The cells that I fill data with, I want them to be read-only to the users. How can I do this?

like image 858
gizgok Avatar asked Aug 24 '10 19:08

gizgok


People also ask

How do you make certain cells Uneditable?

Select the column you want to protect, right Click->Format Cells->Protection, select the "Locked" check box. Review tab->Protect Sheet, select the "Protect worksheet and contents of locked cells" check box and protect the sheet using a password.

How do I lock cells in Excel to avoid editing?

Select the cells you want to lock. On the Home tab, in the Alignment group, click the small arrow to open the Format Cells popup window. On the Protection tab, select the Locked check box, and then click OK to close the popup.


1 Answers

Depends on how you want to select the range. This is just one cell. If you go back to J1 and change the value, you should get prompted.

Private Sub Worksheet_Change(ByVal Target As Range)
  Range("J1").Select
  Selection.Locked = True
  ActiveSheet.Protect Contents:=True
  Range("K1").Select

End Sub

Cells are not locked until the worksheet is protected. By default all cells are set to Locked, so you'll have to unlock cells you want users to be able to change.

like image 128
JeffO Avatar answered Oct 26 '22 23:10

JeffO