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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try like this

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

Forum statistics

Threads
1,224,603
Messages
6,179,856
Members
452,948
Latest member
UsmanAli786

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
Back
Top