0

I would like to make a cell "Cell Name" read-only.

I found this code here but don't know how to use the String value instead of the range:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Not Intersect(Selection, Range("A1:A4")) Is Nothing Then
    Range("B1").Select
  End If
End Sub

How can I adjust this code to suit my needs?

0

Instead of Range("A1:A4") you'd just put Range("Cell Name").

BTW, the code you posted doesn't make the cell readonly; it just makes it hard to select any cell in the range as long as VBA is enabled. It's still possible to edit the cell using VBA, or Excel 4 Macros, or an Add-In, or a number of other tricks.

  • Oh ? is there any function that could turn the cell readonly? – Dido006 Jul 17 '14 at 16:29
  • You have to protect the sheet (optionally with a password) -- that makes all the cells readonly. Then selectively enable certain cells that you want. Look up cell protection in the Excel documentation. If you're in Excel 2007 or later (you should be), check out the "Changes" area of the "Review" tab on the Ribbon. – Snowbody Jul 17 '14 at 16:46
  • Yes i found this functionality on 2007, however, i'd prefer a bit of code to disable any modification on that cell, because its location is unknown and can change, or some columns can be added or removed. – Dido006 Jul 17 '14 at 17:07
  • You can also change the protection on cells from VBA. Check out mrexcel.com/forum/excel-questions/… – Snowbody Jul 17 '14 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.