View Full Version : a string as address in range


pawelch
02-14-2011, 04:30 AM
Dear all

I have been struggling to find an answer to my problem regarding range in vba...

What I want is the following:


Dim aNames() As String
Dim aAddresses() As Range
...
...
Do While iIndex < iCounter
aNames(iIndex) = ActiveCell.Address
Set aAddresses(iIndex) = Range(aNames(iIndex))
iIndex = iIndex + 1
ActiveCell.Offset(0, 1).Select
Loop
In other words I am trying to get all addresses of cells within a given range of a row. The problem I come across is how can I use my stored data, because the following does not work:

" & Range(aAddresses(1).Address).Value & "Thank you in advance for any help and suggestion!

Brianwarnock
02-14-2011, 11:41 AM
Don't know what you are trying to do but aNames will have the addresses in so

Range(aNames(1)).Value = "afdsa"

will put that in A1 if A1 is the active cell at the start.

Hope that helps.

Oh and I had to define the number of elements in the array.

Brian

pawelch
02-17-2011, 01:35 AM
Hi,

what I was trying to understand why

" & Range(aAddresses(1).Address).Value & "did not work and

" & Range("B2").Value & "
did. Of course I tried:

& Range(""&aAddresses(1).Address&"").Value & I was trying to look for an answer to this problem. I have recently found an alternative solution, but thank you anyway for your response.