'Group by' facility?

  • Thread starter Thread starter Steve W
  • Start date Start date
S

Steve W

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
 
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.
 
Treating it as a Jet SQL source sounds useful. How do I do that?

Thanks
SW
 
SW said:
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/default.asp?url=/library/en-us/dnclinic/html/scripting03092004.asp

Jamie.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top