Hi
I've had a look at this (I don't connect to excel by ODBC - always put data in a database, so have learned something hear).
I woud seem that the Left() function works OK, but cannot get the IIF() function to work, which I suggext is the problem (works ok with Access connection!).
My only suggestion is to add another field (column) called, say, 'NotDR' to the spreadsheet to do that part of the calculation there ie. somethink like
=IF(AND(LEFT(C2,1)<>"R",LEFT(C2,1)<>"D"),1,0)
and then add Sum(NotRD) to the query like
Code:
Private Sub CommandButton1_Click()
Dim rsItems As Object
Dim arrItems
Dim strCnn As String
Dim strSQL As String
strCnn = "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=C:\Book3.xls;DefaultDir=c:\;"
Set rsItems = CreateObject("ADODB.Recordset")
strSQL = "SELECT PartyCode, Count(Cost), Sum(Cost), Left(BillNo,1) as Lft"
strSQL = strSQL & ", Sum(NotDR) as SUMNotDR "
strSQL = strSQL & " FROM [A$] "
strSQL = strSQL & " GROUP BY PartyCode,Left(BillNo,1) "
strSQL = strSQL & " Order By Left(BillNo,1)"
rsItems.Open strSQL, strCnn, , 1
arrItems = rsItems.GetRows
arrItems = Application.Transpose(arrItems)
' ComboBox1.List = arrItems
End Sub
HTH !?
MTB