?
Solved

Store vlookup data in macro code?

Posted on 2007-03-28
6
Medium Priority
?
238 Views
Last Modified: 2012-06-27
I've got a macro that references a static spreadsheet for a vlookup in my Personal.XLS macro folder.  Now whenever I start or shut down Excel, it asks me if I want to update or save the changes to my Personal Macro Workbook.  Very annoying.  Is there some way to move a simple two column, 60 row dataset into the macro itself?
0
Comment
Question by:Rossamino
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 18810920
There are ways but it might be easier to set the IsAddin property of your Personal workbook to True - that will eliminate that prompt. To do so, open Personal.xls, press ALT+F11, open the ThisWorkbook code module, press F4 to open the Properties window, find the IsAddin property and set it to True.

Kevin
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 18810943
If you want to create a two dimensional array of constants in your macro then use this syntax:

   Dim X As Variant
   X = [{1,2;3,4;5,6}]

where commas separate values in a row and the semicolon separates rows.

Kevin
0
 

Author Comment

by:Rossamino
ID: 18811715
zorvek, Assuming I do this:

Dim arStates As Variant
arStates = [{Alabama,AL;Alaska,AK;...Wyoming,WY}]

how would a guy go about referencing arStates in a vlookup?

the current code looks like this (its all on one line):
    Range("M2").Value = "=if(iserror(vlookup(L2,'C:\[States.xls]States'!B$1:B$59,1,0)), if(iserror(vlookup(L2,'C:\[States.xls]States'!A$1:B$59,2,0)), concatenate(""zz"" & L2), vlookup(L2,'C:\[States.xls]States'!A$1:B$59,2,0)), vlookup(L2,'C:\[States.xls]States'!B$1:B$59,1,0))"

It seems to me that I'd have to rewrite the vlookup function in VBA and apply the result directly instead of pasting the function.  Yes?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 18811774
You can't use most Excel functions in VBA with arrays. I suggest using a collection:

   Dim StateNames As Collection
   Dim StateAbreviation As String
   
   Set StateNames = New Collection
   StateNames.Add "CA", "California"
   StateNames.Add "TX", "Texas"
   StateNames.Add "FL", "Florida"
   
   StateAbreviation = StateNames("Texas")

Kevin
0
 

Author Comment

by:Rossamino
ID: 18819378
So when I build this collection, how do I go about using it if I can't use vlookup on the thing?
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 1200 total points
ID: 18819457
Whenever you need to convert a state name to a state abbreviation use the collection like this:

   StateAbreviation = StateNames("Texas")

StateAbreviation will now be "TX".

Kevin
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question