Excel ADO Select Distinct from2 column with numeric value

SevenDP

New Member
Joined
Mar 10, 2016
Messages
21
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:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top