Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland asked on

Excel VBA - Join/merge two ranges as you would with SQL

Hi

I have two ranges that come from separate database tables pasted into Excel
They both have a column called ID that I want to use to merge the data as one would
do in a SQL join query. What VBA code would I use to do this?
Microsoft Excel

Avatar of undefined
Last Comment
Murray Brown

8/22/2022 - Mon
Saqib Husain

What happens if the data is different for the two IDs?
andrew_man

Do you think the ODBC is suitable for your case?
Rory Archibald

There are various different ways. Which is best would depend on what you are doing with the data, but it would be simpler to extract the data using a query that joins the two tables in the first place if you can?
Your help has saved me hundreds of hours of internet surfing.
fblack61
printnix63

If the two tables contain the same sort of data,
can't you use a Union query to combine them?

Select table1.id, table1.field from table1
Union
Select table2.id,table2.otherfield from table2

The two queries combined by Union must have the same typeset of Felds in their Field definition, but they do not need to have the same names normally.

Hope this helps
ASKER
Murray Brown

Hi

This has to be done in Excel. The tables come from a SAP dump where there is a lot of security around user permissions etc
Saqib Husain

If you can give more details (preferably with a sample excel file) then probably someone can write a macro for you.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
andrew_man

Yes, agreed!
SOLUTION
Jerry Paladino

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Murray Brown

Thanks for the help