ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Named range in an array (https://www.excelbanter.com/excel-programming/372292-named-range-array.html)

Frigster

Named range in an array
 
Hi,

I have five cells on a row (A1:A5). This range is named "xyz".
How can I transform this range in an array with VB code?

Thank you.
Paolo.



Tom Ogilvy

Named range in an array
 
dim v as Variant
v = Range("xyz").Value

for i = 1 to 5
msgbox v(i,1)
Next


If you want a 1D array

v = application.Transpose("xyz")

for i = 1 to 5
msgbox v(i)
Next

--
Regards,
Tom Ogilvy


"Frigster" wrote:

Hi,

I have five cells on a row (A1:A5). This range is named "xyz".
How can I transform this range in an array with VB code?

Thank you.
Paolo.




Alan Beban

Named range in an array
 
Tom Ogilvy wrote:
dim v as Variant
v = Range("xyz").Value

for i = 1 to 5
msgbox v(i,1)
Next


If you want a 1D array

v = application.Transpose("xyz")'<---A typo:v = application.Transpose(Range("xyz"))

for i = 1 to 5
msgbox v(i)
Next

Alan Beban

ccroche

Named range in an array
 
Sorry, I think there is again a typo ...

If you want a 1D array
v = application.WorkSheetFunction.Transpose(Range("xyz "))

Christian CROCHE

Tom Ogilvy

Named range in an array
 
No, there is no requirement to use WorksheetFunction. No typo.

--
Regards,
Tom Ogilvy


"ccroche" wrote in message
...
Sorry, I think there is again a typo ...

If you want a 1D array
v = application.WorkSheetFunction.Transpose(Range("xyz "))

Christian CROCHE




JE McGimpsey

Named range in an array
 
One way:

Dim arr As Variant
arr = Range("A1:A5").Value


In article ,
"Frigster" wrote:

Hi,

I have five cells on a row (A1:A5). This range is named "xyz".
How can I transform this range in an array with VB code?



All times are GMT +1. The time now is 09:40 PM.

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