refer to cell in range

G

Guest

hi! i have a named range. in a loop i want to loop through the different
cells in the range. i do not know how to do this. My named range:

Dim varCounterpartyData As Variant
varCounterpartyData =
ThisWorkbook.Sheets("Counterparty").Range("CounterpartyIndataRange").Value

but how do i refer to the first cell in the range? or rather the value that
is in the first cell. any help much appreciated!
 
N

NickHK

Arne,
One way:

Dim Cell as range

for each cell in Range("YourName")
debug.print cell.address
next

And the first cell:
MsgBox Range("YourName")(1).Value
MsgBox Range("YourName").Cells(1, 1).Value

Qualify the above ranges as required.

NickHK
 
G

Guest

Try this. I've assumed you named your range on the worksheet and don't want
to define it at VBA level.


Sub marine()
Dim varCounterpartyData As Range
For Each c In Range("varCounterpartyData")
MsgBox (c.Value)
Next c

End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top