ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop using cell names (https://www.excelbanter.com/excel-programming/288704-loop-using-cell-names.html)

matt

Loop using cell names
 
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.

Bob Phillips[_6_]

Loop using cell names
 
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" wrote in message
...
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.



John Wilson

Loop using cell names
 
Matt,

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

John

"Matt" wrote in message
...
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.



Trevor Shuttleworth

Loop using cell names
 
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" wrote in message
...
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.




All times are GMT +1. The time now is 08:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com