tags:

views:

39

answers:

5

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

A: 

Not sure if this is what you want.
Please read all the posts.

ring0
A: 

In excel you can go to the Protection menu and specify which cells would require a password to modify. You can specify multiple ranges as well.

Hope this is what you were looking for.

DeaconnFrost
+1  A: 

You can try protecting cells. Or you can code it yourself using a SelectionChange handle event... :

   Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      If Not Intersect(Selection, Range("A24:A50")) Is Nothing Then
        Range("B1").Select
      End If
    End Sub
froadie
+1  A: 

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.

Jeff O
If I want to make this work for a rang eof cells,How can I do that.Pardon my lack of knowledge,I'm new to programming.
gizgok
Range("A1:K47")
Jeff O
This is making all cells readonly..am I making some mistake.Private Sub Worksheet_Change(cellrange As String) Range(cellrange).Select Selection.Locked = True ActiveSheet.Protect Contents:=TrueEnd Sub
gizgok
Sorry, not sure what code to use, but edited response.
Jeff O
+1  A: 

In these circumstances I often find the best way is to lock the sheet, but only for the user by using the UserInterfaceOnly argument which still allows unrestricted programmatic interaction with the sheet.

ActiveSheet.ProtectUser InterfaceOnly:=True

There are various other arguments that can be set that will still allow the user to filter, sort etc. should this be required, the Help file has a full list.

Lunatik