VBA, SQL, and distinct count

Bastos

New Member
Joined
May 23, 2012
Messages
3
Hi everyone,

after a long search, on the forum and on the rest of the web, i couldn't find my answer, so i'm asking you now.

I have a table (excel spreadsheet), which size is variable. Two columns are valuable to me right now, "TBF" (which is a number), and "Channel" (which has 7 different string values such as "BI", "BO", "BA", "BC", etc).

I would like, using a SQL request (on which i'm a newbie), to get a table with distinct count of BI, BO, BC, BA, etc for each TBF value.
ex:
TBF BI BO BA BC
1 37 15 8 2
2 20 5 2 0
3 25 10 5 2
etc...

I don't want to use a "for" loop, for time issues (tried already). Pivot table could be a solution, but if some value don't exist (say there's no "BC" at all), it doesn't appear. So not possible.

I tried this request:
select distinct TBF, count(distinct Channel) from " & "[" & "IOHWL_SE" & "$A1:O" & lrIO & "] order by TBF
but i'm getting "Syntax error (missing operator)" error message from Excel... and all my searches were not useful...

Many thanks for your help!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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