LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default Can VBA use array constants

This question follows from
<http://groups.google.com/g/8077ff07/...18cd6d29d06f79
c.
In VBA, I want to lookup a column number which refers to a London
Underground line name.

My first version using VLOOKUP was:
Dim colIndex ' Translation of Line to a column number

ActiveCell.Formula = "=VLOOKUP(""" & Line & """," _
& "{""Bakerloo"",5;""Central"",6, ...},2,TRUE)"
colIndex = ActiveCell.Value

My second version using MATCH used this line:
ActiveCell.Formula = "=4+MATCH(""" & Line & """," _
& "{""Bakerloo"",""Central"", ...}, 1)"

(With both those versions both "Central" and "Central line" match.)

My third version using the VBA find function used the following code:
Dim lines As Range ' at module level
Set lines = Range("E1:O1") ' in a public subroutine
colIndex = lines.Find(Line).Column

(With this version, "Central line" (unsurprisingly) does not match.)

Is it possible to use an array constant for the range in such code?
If so, how?

I got a 1004: "Method 'Range' of object '_Global' failed" with
Set lines = Range(Array("Bakerloo", "Central", "Circle", ...))

As it happens, I am happy with the third method.
I am not happy with my ignorance. ;)
--
Walter Briscoe
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Constants kittronald Excel Worksheet Functions 0 June 15th 11 12:04 AM
unions, intersections or array constants Loadmaster Excel Worksheet Functions 24 May 6th 09 08:11 PM
not sure on constants Curt Excel Programming 3 April 10th 07 07:04 PM
Declaring array constants at module level Microsoft Forum Excel Programming 2 January 24th 05 06:31 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"