Using the offset function

grahamiwa

New Member
Joined
Mar 14, 2011
Messages
30
I have a relatively simple scheduling spreadsheet I am trying to make "Idiot" proof.
The data range of the spreadsheet is 8 columns wide and generally 100 rows deep.

I have the code to check if each cell is empty and only lock the cells with data. This works well.

The problem I have at the moment is that the only way I know how to write the select cell part is by repeatdly naming the cell like this

Range("C33").Select
If Range("C33").Value = "" Then
Selection.Locked = False
Else
Selection.Locked = True
End If

Then repeating it


Range("E33").Select
If Range("E33").Value = "" Then
Selection.Locked = False
Else
Selection.Locked = True
End If

And so on.

I would prefer if I could specify the complete data range eg C10:J110
then just have the right code check each cell within that range. I dont know how to write the correct offset code and then incorporate it with the "If" code

Any help will be greatly appreciated
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try like this

Code:
Dim c As Range
For Each c In Range("C10:J110")
    c.Locked = c.Value <> ""
Next c
 

grahamiwa

New Member
Joined
Mar 14, 2011
Messages
30
Excellent It works well

It got rid of about 25 pages of code

I am really happy thanks
 

Watch MrExcel Video

Forum statistics

Threads
1,114,584
Messages
5,548,883
Members
410,882
Latest member
ADJ
Top