Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Protect cells IF the cell is not empty

Planning to make this excel file in which users should be able to fill in new
data in empty cells but not in cells that have data in them already.

I.e. IF Cell is empty, the user is allowed to fill in data. IF Cell is not
empty, cell is protected.

This way the users can only add new data to the chart but not modify old data.

thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Protect cells IF the cell is not empty

right click on the sheet tab and put in code like this:

Before doing that, unlock all your cells, then select filled cells and lock
those. Then protect the sheet with your password. Just for consideration,
if the user makes a typo when they enter data or enter data in the wrong
cell, there is no correcting it.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHandler
Me.Unprotect Password:="ABCD"
For Each cell In Target
If Not IsEmpty(cell) Then
cell.Locked = True
End If
Next
ErrHandler:
Me.Protect Password:="ABCD:"
End Sub


--
Regards,
Tom Ogilvy


"Boka" wrote in message
...
Planning to make this excel file in which users should be able to fill in

new
data in empty cells but not in cells that have data in them already.

I.e. IF Cell is empty, the user is allowed to fill in data. IF Cell is not
empty, cell is protected.

This way the users can only add new data to the chart but not modify old

data.

thanks in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Protect cells IF the cell is not empty

Thanks for the help but unfortunately your solution only worked once. Only
one cell got locked (stayed locked) after typing something into it. The other
cells were modifyable over and over again.

It's strange since looking at your code it looks as it should work.

Any suggestions?

"Tom Ogilvy" wrote:

right click on the sheet tab and put in code like this:

Before doing that, unlock all your cells, then select filled cells and lock
those. Then protect the sheet with your password. Just for consideration,
if the user makes a typo when they enter data or enter data in the wrong
cell, there is no correcting it.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHandler
Me.Unprotect Password:="ABCD"
For Each cell In Target
If Not IsEmpty(cell) Then
cell.Locked = True
End If
Next
ErrHandler:
Me.Protect Password:="ABCD:"
End Sub


--
Regards,
Tom Ogilvy


"Boka" wrote in message
...
Planning to make this excel file in which users should be able to fill in

new
data in empty cells but not in cells that have data in them already.

I.e. IF Cell is empty, the user is allowed to fill in data. IF Cell is not
empty, cell is protected.

This way the users can only add new data to the chart but not modify old

data.

thanks in advance




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Protect cells IF the cell is not empty

Tom's code (with one modification) worked fine for me:

Me.Protect Password:="ABCD:"
became
Me.Protect Password:="ABCD"

And I made sure the cells that could change were unlocked to start.

(I'm guessing that Tom saves lots of stuff to his D: drive (muscle memory
strikes again!) <vbg.)



Boka wrote:

Thanks for the help but unfortunately your solution only worked once. Only
one cell got locked (stayed locked) after typing something into it. The other
cells were modifyable over and over again.

It's strange since looking at your code it looks as it should work.

Any suggestions?

"Tom Ogilvy" wrote:

right click on the sheet tab and put in code like this:

Before doing that, unlock all your cells, then select filled cells and lock
those. Then protect the sheet with your password. Just for consideration,
if the user makes a typo when they enter data or enter data in the wrong
cell, there is no correcting it.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHandler
Me.Unprotect Password:="ABCD"
For Each cell In Target
If Not IsEmpty(cell) Then
cell.Locked = True
End If
Next
ErrHandler:
Me.Protect Password:="ABCD:"
End Sub


--
Regards,
Tom Ogilvy


"Boka" wrote in message
...
Planning to make this excel file in which users should be able to fill in

new
data in empty cells but not in cells that have data in them already.

I.e. IF Cell is empty, the user is allowed to fill in data. IF Cell is not
empty, cell is protected.

This way the users can only add new data to the chart but not modify old

data.

thanks in advance





--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sum of cells until reach empty cell phsdave Excel Worksheet Functions 4 January 24th 10 11:15 AM
count non empty cells if other cell has certain value Nico Excel Discussion (Misc queries) 5 May 18th 06 10:40 AM
protect cells based on another cell Neil Excel Worksheet Functions 6 August 9th 05 03:13 PM
VBA to copy to empty cell directly below a cell when analogous cells in different column have same value as each other? Steven Rosenberg Excel Programming 0 August 5th 03 06:10 AM
VBA to copy to empty cell directly below a cell when analogous cells in different column have same value as each other? SROSENYC Excel Programming 1 August 5th 03 04:34 AM


All times are GMT +1. The time now is 12:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"