Solved

Store vlookup data in macro code?

Posted on 2007-03-28
6
231 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
  • 4
  • 2
6 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
Comment Utility
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)
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
Comment Utility
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
Comment Utility
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 400 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now