Loop using cell names

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a group of cells that I have renamed. They are cell1,cell2,cell3 and so on up to 30. Is it possible to take the cell names and extract the number in the cell name so that I can use the number in a loop. I would like to protect these cells as the loop progresses. Thanks.
 
Matt,

This may help

For i = 1 To 3
Debug.Print Range("cell" & i).Value
Next i

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Matt said:
I have a group of cells that I have renamed. They are cell1,cell2,cell3
and so on up to 30. Is it possible to take the cell names and extract the
number in the cell name so that I can use the number in a loop. I would
like to protect these cells as the loop progresses. Thanks.
 
Matt,

Sub TestMe()
Dim x As Integer
For x = 1 To 30
Range("cell" & x).Locked = True
Next x
End Sub

John

Matt said:
I have a group of cells that I have renamed. They are cell1,cell2,cell3
and so on up to 30. Is it possible to take the cell names and extract the
number in the cell name so that I can use the number in a loop. I would
like to protect these cells as the loop progresses. Thanks.
 
Matt

this example demonstrates how to loop around the cells:

Sub LoopRoundCellNames()
Dim i As Long
For i = 1 To 30
On Error GoTo CellExit
MsgBox Range("Cell" & i).Name.Name & _
" " & _
Range("Cell" & i).Address
Next 'i
CellExit:
End Sub

What do you mean by "protect the cells"? The cells will be protected
(locked) by default but you need to protect the sheet for this to have any
effect.

Regards

Trevor


Matt said:
I have a group of cells that I have renamed. They are cell1,cell2,cell3
and so on up to 30. Is it possible to take the cell names and extract the
number in the cell name so that I can use the number in a loop. I would
like to protect these cells as the loop progresses. Thanks.
 
Back
Top