ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Declaring 2 dimensional arrays (https://www.excelbanter.com/excel-programming/345691-declaring-2-dimensional-arrays.html)

Dan[_49_]

Declaring 2 dimensional arrays
 
I want to have an array - Item(100,2) where the first column is a string and
the second column is an integer.

Is this possible? If so how do I declare the variable.

Dan



Chip Pearson

Declaring 2 dimensional arrays
 
Declare the array type as Variant. It can hold any data type.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Dan" wrote in message
...
I want to have an array - Item(100,2) where the first column is
a string and
the second column is an integer.

Is this possible? If so how do I declare the variable.

Dan





Dan[_49_]

Declaring 2 dimensional arrays
 
Thanks, I thought there was a way.

Dan
"Chip Pearson" wrote in message
...
Declare the array type as Variant. It can hold any data type.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Dan" wrote in message
...
I want to have an array - Item(100,2) where the first column is a string
and
the second column is an integer.

Is this possible? If so how do I declare the variable.

Dan







Alan Beban[_2_]

Declaring 2 dimensional arrays
 
For the particular case you describe, I believe you can also use

Dim Item(100,2) As String

I have no view on whether that is "better" than declaring it as a
Variant type.

Alan Beban

Dan wrote:
Thanks, I thought there was a way.

Dan
"Chip Pearson" wrote in message
...

Declare the array type as Variant. It can hold any data type.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Dan" wrote in message
.. .

I want to have an array - Item(100,2) where the first column is a string
and
the second column is an integer.

Is this possible? If so how do I declare the variable.

Dan







MrShorty[_30_]

Declaring 2 dimensional arrays
 

For my own education, what would be advantages and disadvantages to
using a user-defined type for this kind of situation?

Type myitems
a as string
b as integer
End Type

Sub test()
Dim item(100) as myitems

Code:
--------------------

End sub

where the variable is referenced using item(i).a="somestring" and item(i).b=someinteger


--
MrShorty
------------------------------------------------------------------------
MrShorty's Profile: http://www.excelforum.com/member.php...o&userid=22181
View this thread: http://www.excelforum.com/showthread...hreadid=485333



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

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