PDA

View Full Version : [VBA]:How to use VBA to merge 2 sheets into one with the same ID



jackwong730
02-29-2016, 07:48 AM
How to use VBA to merge 2 sheets into one with the same ID

15507
15508
15509 <- there is the expected result.

Thanks!

JKwan
02-29-2016, 09:51 AM
give this a spin

jackwong730
03-01-2016, 08:20 AM
They are not SQL.
The data stored in Excel only.
It should not involved in SQL.
Can : stSQLstring = "Select [Sheet1$].[ID], [Sheet1$].[Name], " & _ "[Sheet2$].[Purchase] From " & _
"([Sheet1$] Left Join [Sheet2$] On " & _
"[Sheet1$].[ID] = [Sheet2$].[ID]);"
do the mapping?

Anyway, thank you for your help!:yes

JKwan
03-01-2016, 01:24 PM
Have you try running it? Yes, I used SQL to extract, that is the beauty of programming, if you know how to do it, you can do anything.

Put your info onto Sheet1 and Sheet2 just like what you have in your question and run the code. (never mind - I already did this for you - so just run the code)

jackwong730
03-01-2016, 04:40 PM
Tried. Thanks anyway. Going to understand it and reproduct it!