By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,002 Members | 1,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,002 IT Pros & Developers. It's quick & easy.

Converting XLM macro into VBA

P: 3
I am very Experiences in Excel but very new to VBA & I am struggling to convert an old XLM macro into Visual Basic

The Macro helps you to compile the INDEX/MATCH formula (very similar to Vlookup but much more adaptable.

The FORMULA is =INDEX(Column(s) where data to be selected is held,MATCH(cell containing info to be matched,column where matching data is held,0),1)

The XLM code used =

Match (m)
cell1=REFTEXT(INPUT("select cell containing info to be matched & click 'OK'",8))
cell1=RELREF(TEXTREF(cell1),ACTIVE.CELL())
cell2=REFTEXT(INPUT("Highlight column where matching data is held & click 'OK'",8))
Range=REFTEXT(INPUT("Highlight column(s) where data to be selected is held & click 'OK'",8))
=FORMULA("=INDEX("&Range&",MATCH("&cell1&","&cell2 &",0),1)")
=FORMULA.REPLACE("H(","H($",2,1,TRUE,FALSE)
=RETURN()

This is a very useful Macro & I would be very grateful if anyone can help
Oct 4 '07 #1
Share this Question
Share on Google+
4 Replies


kadghar
Expert 100+
P: 1,295
I am very Experiences in Excel but very new to VBA & I am struggling to convert an old XLM macro into Visual Basic

The Macro helps you to compile the INDEX/MATCH formula (very similar to Vlookup but much more adaptable.

The FORMULA is =INDEX(Column(s) where data to be selected is held,MATCH(cell containing info to be matched,column where matching data is held,0),1)
(...)
I think you can create a public function in a module, this will allow you to use it in your VBA code or in your worksheet as an excel function.

It should be something like:

Public Function IndexMatch(byval Cell1, Cell2, Range1)
'Write here the code
End Function

Since you're declaring everything as a variant, you can asign a full range into Range1

I mean, if you write

dim a
a = range(cells(1,1), cells(5,5))
IndexMatch( cells(1,1) , cells(1,2) , a)

will do

Still im not sure that you can use a function that has an array as an input as an excel function in the worksheet. But you can use it in any other function or procedure, and it'll be quite fast if you import a range the way i wrote before.
Oct 4 '07 #2

P: 3
I would still prefer a Macro that I can share with collegues. The original xlm that I wrote allowed you to match data contained in different workbooks, I understand that as a functionn this would be difficult to achieve. However, your suggestion has given me another option & I will read up about Public Functions.

I am very grateful for this lead & your quick response.

Thank you very much.

Tony
Oct 5 '07 #3

kadghar
Expert 100+
P: 1,295
Remember you can write into a module both: functions and procedures. Procedures writen in a VBA module are the "macros". they can call the functions you created as well as other procedures.

VBA is not a very powerful tool, but you can achieve to work with multiple excel workbooks, sheets, even have many excel applications at the same time.

Take a look around other questions made here before, i'm sure you can find answers for what you're looking for.

And feel free to post any other doubt you have.
Oct 5 '07 #4

P: 3
I am very new to VBA which seems a lot more complicated than the old XL Macro Language so I will need to do a lot more studying to understand your advice.

I am very grateful that you have pointed me in the right direction for this study & I will do as you suggest

Thanks again

Tony
Oct 5 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.