ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   'Group by' facility? (https://www.excelbanter.com/excel-programming/324557-group-facility.html)

Steve W[_2_]

'Group by' facility?
 
Hi,

I've a lot of csv files to process. In each one I need to summ some columns
where one or two other columns are the same.
In a database table this would be easy using a SQL 'group by' statement.
Is there a similar method I could use in VBA?

Thanks in advance
SW



Rob van Gelder[_4_]

'Group by' facility?
 
Pivot tables are about as close as you'll get. Unless you want to treat the
same workbook as a Jet SQL source and query it.


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Steve W" wrote in message
...
Hi,

I've a lot of csv files to process. In each one I need to summ some
columns where one or two other columns are the same.
In a database table this would be easy using a SQL 'group by' statement.
Is there a similar method I could use in VBA?

Thanks in advance
SW




SW[_5_]

'Group by' facility?
 
Treating it as a Jet SQL source sounds useful. How do I do that?

Thanks
SW

"Rob van Gelder" wrote in message
...
Pivot tables are about as close as you'll get. Unless you want to treat

the
same workbook as a Jet SQL source and query it.


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Steve W" wrote in message
...
Hi,

I've a lot of csv files to process. In each one I need to summ some
columns where one or two other columns are the same.
In a database table this would be easy using a SQL 'group by' statement.
Is there a similar method I could use in VBA?

Thanks in advance
SW






Jamie Collins

'Group by' facility?
 
SW wrote:
Treating it as a Jet SQL source sounds useful. How do I do that?


Sub just_four_lines()
Dim rs As Object
Set rs = CreateObject("ADOR.Recordset")
rs.Open _
"SELECT COUNT(*) as customer_count," & _
" Country FROM MyFile#csv" & _
" GROUP BY Country" & _
" ORDER BY COUNT(*), Country", _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\MyFolder\;" & _
"Extended Properties='Text;HDR=Yes';"
Sheet1.Range("A1").CopyFromRecordset rs
End Sub

For more details <g, see:

http://msdn.microsoft.com/library/de...ng03092004.asp

Jamie.

--



All times are GMT +1. The time now is 03:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com