ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Protecting non contiguous cells (https://www.excelbanter.com/excel-programming/322472-protecting-non-contiguous-cells.html)

nospaminlich

Protecting non contiguous cells
 
I am trying to protect all cells in a range with a value 0 so that users can
only input into the non blank cells in the range.

I've tried this

Sub test()

Range("A2:I10").Select
If Value = 0 Then
Cells.Locked = False
End If

End Sub

but it Unlocks all cells on the Worksheet so I'm obviously doing something
very wrong.

I'd be grateful for some help please

JulieD

Protecting non contiguous cells
 
Hi

try

sub test()
For Each c In Range("A2:I10")
If c.Value < 0 Then
c.Locked = False
End If
Next
end sub

bit confused about which cells you want to protect - so let me know if the
above gives you what you want.

Cheers
JulieD


"nospaminlich" wrote in message
...
I am trying to protect all cells in a range with a value 0 so that users
can
only input into the non blank cells in the range.

I've tried this

Sub test()

Range("A2:I10").Select
If Value = 0 Then
Cells.Locked = False
End If

End Sub

but it Unlocks all cells on the Worksheet so I'm obviously doing something
very wrong.

I'd be grateful for some help please




Don Guillett[_4_]

Protecting non contiguous cells
 
try a loop
for each c in range("a2:i10"
if
next

--
Don Guillett
SalesAid Software

"nospaminlich" wrote in message
...
I am trying to protect all cells in a range with a value 0 so that users

can
only input into the non blank cells in the range.

I've tried this

Sub test()

Range("A2:I10").Select
If Value = 0 Then
Cells.Locked = False
End If

End Sub

but it Unlocks all cells on the Worksheet so I'm obviously doing something
very wrong.

I'd be grateful for some help please




nospaminlich

Protecting non contiguous cells
 
Thanks a lot for the replies. Julie's solution modified to "If c.Value = 0
Then" works a treat. Thanks again

JulieD

Protecting non contiguous cells
 
you're welcome and thanks for the feedback

"nospaminlich" wrote in message
...
Thanks a lot for the replies. Julie's solution modified to "If c.Value =
0
Then" works a treat. Thanks again




Thierry H.

Protecting non contiguous cells
 
You might want to test empty cells with c.value ="".

"JulieD" wrote:

you're welcome and thanks for the feedback

"nospaminlich" wrote in message
...
Thanks a lot for the replies. Julie's solution modified to "If c.Value =
0
Then" works a treat. Thanks again






All times are GMT +1. The time now is 04:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com