Array subscript with Variant

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Array subscript with Variant

Post by agibsonsw »

Hello.
I'm placing a range into a (variant) array but I can't reference the array elements:
Dim EmpIDArray As Variant

EmpIDArray = Range("EmpID")
MsgBox EmpIDArray(3) ' generates subscript out of range error.

Am I missing something straightforward? Thanks, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
HansV
Administrator
Posts: 78463
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Array subscript with Variant

Post by HansV »

A range is a two-dimensional array, so you have to use for example EmpIDArray(2, 1).
Best wishes,
Hans

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Array subscript with Variant

Post by agibsonsw »

Thank you. I was scratching my head for a while..
Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.