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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

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,109,453
Messages
5,528,871
Members
409,842
Latest member
mfernandezcean
Top