473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Converting XLM macro into VBA

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
4 4458
kadghar
1,295 Expert 1GB
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
tonyP
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
1,295 Expert 1GB
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
tonyP
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

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

Similar topics

1
by: Juli | last post by:
I am converting a db from 97 to 2002. I have a very simple Find Macro from 97- consists of RunCommand: Find SendKeys: %h{up}%e%n After the conversion.... If I try to run the macro from the...
1
by: Mario Crevits | last post by:
My name is Mario Crevits, I'm from Belgium (Roeselare) and I'm working with Access97 for several years now. We are in an Access97-2000 migration project. I'm writing a wizard for the end-users to...
2
by: John Ortt | last post by:
Hi All, I have a database in Access 97 which works fine but our company is converting from NT4 to XP Pro and in the process changing Office 97 for Office 2003. I have tried to convert the 97...
3
by: John Devereux | last post by:
Hi, I would like to be able to define a number with the preprocessor, then be able to use it to generate both numeric and string constants. For example, #define VERSION_MAJOR 4 #define...
2
by: Paolo | last post by:
I imported a VC++6.0 project into VC++7.1. The conversion operation makes a mess with Preprocessor Definitions, adding a "$(NoInherit)" for each file. For example: I had a DLL project in VC++6.0...
0
by: BCC | last post by:
Hi, in visual studio 6.0, I used to have this great macro that would let me jump from function header to function header in source code... I am now using .NET, and want to try to use the same...
1
by: Thierry Lam | last post by:
Let's say I have the following codes: #define macHOME $HELLOHOME How can I concatenate the above macro into a string, for example I want the following result: char *path =...
23
by: Reggie | last post by:
Hi and TIA. I developed several A2K dbs which are now being run on my clients computer which have been upgraded to Access 03. I'm not sure exactly what they mean but of you know or could point me...
116
by: Dilip | last post by:
Recently in our code, I ran into a situation where were stuffing a float inside a double. The precision was extended automatically because of that. To make a long story short, this caused...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.