Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How can I protect only cells that meet certain conditions?

I want to allow users to enter a value in a cell (say G5) only if another
cell (G21) has a value greater than zero.

If G21 is zero or blank, then I do not want the user to be able to select G5.

This is for Microsoft Xcel 2000.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default How can I protect only cells that meet certain conditions?

You might use a worksheet event. This will undo any entry in any cell if
the cell 16 rows down is not greater than 0
Add the select to move active cell to the next cell down.

===========================================
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False

If Target.Offset(16, 0) <= 0 Then
Application.Undo
' Target.Offset(1, 0).Select
End If

Application.EnableEvents = True

End Sub
===========================================

For a specific cell:
===========================================
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False

If target.address = "$G$5" and Range("G21") <= 0 Then
Application.Undo
' Range("G6").Select
End If

Application.EnableEvents = True

End Sub
===========================================
--
rand451
"Billparsons40" wrote in message
...
I want to allow users to enter a value in a cell (say G5) only if another
cell (G21) has a value greater than zero.

If G21 is zero or blank, then I do not want the user to be able to select
G5.

This is for Microsoft Xcel 2000.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default How can I protect only cells that meet certain conditions?

This one will move the selection:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False

If Target.Address = "$G$5" And Range("G21") <= 0 Then
Target.Offset(1, 0).Select
End If

Application.EnableEvents = True
End Sub

--
rand451
"STEVE BELL" wrote in message
news:I3Mme.10044$3u3.1713@trnddc07...
You might use a worksheet event. This will undo any entry in any cell if
the cell 16 rows down is not greater than 0
Add the select to move active cell to the next cell down.

===========================================
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False

If Target.Offset(16, 0) <= 0 Then
Application.Undo
' Target.Offset(1, 0).Select
End If

Application.EnableEvents = True

End Sub
===========================================

For a specific cell:
===========================================
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False

If target.address = "$G$5" and Range("G21") <= 0 Then
Application.Undo
' Range("G6").Select
End If

Application.EnableEvents = True

End Sub
===========================================
--
rand451
"Billparsons40" wrote in message
...
I want to allow users to enter a value in a cell (say G5) only if another
cell (G21) has a value greater than zero.

If G21 is zero or blank, then I do not want the user to be able to select
G5.

This is for Microsoft Xcel 2000.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 222
Default How can I protect only cells that meet certain conditions?

"Billparsons40" wrote:

I want to allow users to enter a value in a cell (say G5) only if another
cell (G21) has a value greater than zero.

If G21 is zero or blank, then I do not want the user to be able to select G5.

This is for Microsoft Xcel 2000.


Something along these lines should do the trick:-

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("G21") 0 Then
ActiveSheet.Unprotect
Range("G5").Locked = False
ActiveSheet.Protect
End If
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default How can I protect only cells that meet certain conditions?

Yes but remember to have the alternative ... to set the cell's protection to
locked if G21 is not in the permitted condition.

"bigwheel" wrote in message
...
"Billparsons40" wrote:

I want to allow users to enter a value in a cell (say G5) only if another
cell (G21) has a value greater than zero.

If G21 is zero or blank, then I do not want the user to be able to select
G5.

This is for Microsoft Xcel 2000.


Something along these lines should do the trick:-

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("G21") 0 Then
ActiveSheet.Unprotect
Range("G5").Locked = False
ActiveSheet.Protect
End If
End Sub



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
lookup function to meet two conditions Sean Excel Worksheet Functions 2 September 3rd 08 02:43 PM
If formula with two conditions to meet Carolina Excel Worksheet Functions 7 August 28th 08 05:25 PM
count pieces of records meet conditions in different columns Amy Excel Worksheet Functions 1 July 19th 07 10:39 AM
Array to meet conditions Erin Excel Worksheet Functions 5 January 16th 07 08:37 PM
counting cells in a data range that meet 3 specific conditions bekah7 Excel Discussion (Misc queries) 3 October 1st 05 06:21 AM


All times are GMT +1. The time now is 04:24 AM.

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

About Us

"It's about Microsoft Excel"