Excel ADO Select Distinct from2 column with numeric value


New Member
Mar 10, 2016
Hi guys

Please help...
I have data:

District; Type; Price1; Price2
JKT; Type1; 100;
JKT; Type1; 101;
JKT; Type1; 104;
JKT; Type1; ; 111
JKT; Type1; ; 22
JKT; Type2; 50;
JKT; Type2; ; 150
JKT; Type2; ; 15
SMG; Type2; ; 44
SMG; Type2; ; 144

expected result:
Same District & Type, then Price1 &Price2 will become 1 row
if there are another same district & type, it will create new row

District; Type; Price1; Price2
JKT; Type1; 100; 111
JKT; Type1; 101; 22
JKT; Type1; 104;
JKT; Type2; 50; 150
JKT; Type2; ; 15
SMG; Type2; ; 44
SMG; Type2; ; 144

can achieve it using ADO SQL ?

sql = "SELECT DISTINCT [District], [Type], [Price1], '' FROM [Hasil$A4:D216] WHERE [Price1] <> 0 ORDER BY [District], [Type] UNION ALL"
sql = sql & " SELECT DISTINCT [District], [Type], '', [Price2] FROM [Hasil$A4:D216] WHERE [Price2] <> 0 ORDER BY [District], [Type]"
but can not group it (GROUP BY [District], [Type] got error)

or there are other ways to do that ?
many thanks guys
Last edited:

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics

  • Copy entire row if CountA <>0 to another sheet
    [B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
  • Select last used Row in Table
    I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
  • excel workbook: do not allow certain file name
    Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
  • fixing problem autofilter
    hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
  • “Weight”
    Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
  • How to capitalize everything before a certain character?
    In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...