Count number of records - QueryTable.CommandText property (Excel) - VBA and Power Query

Iron Contributor

Why will the following SQL statement not work re: count number of records and group by ProductName:

 

Set qtQtrResults = _ Workbooks(1).Worksheets(1).QueryTables(1)

With qtQtrResults

  .CommandType = xlCmdSQL

  .CommandText = "SELECT ProductName, Count(*) FROM Products GROUP BY ProductName"

 .Refresh

End With

0 Replies