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
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,117
Messages
5,835,484
Members
430,358
Latest member
zzc1128

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top