PDA

View Full Version : [SOLVED:] VBA Query to filter #N/A



Kaniguan1969
10-06-2014, 05:37 PM
I have an Excel VBA Query that perform to filter all #N/A value that result from a formula. I need to filter the column Model with #N/A values. Just wondering if my codes is correct or wrong "WHERE isnull(e.Model) ". May I ask your assistance please. Thank you.
Below is my VBA Query.


Dim con As Object: Set con = CreateObject("ADODB.Connection")
Dim rec As Object: Set rec = CreateObject("ADODB.Recordset")
Dim datasource As String
datasource = ThisWorkbook.FullName

Dim sconnect As String
sconnect = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & datasource & ";" & _
"Extended Properties=""Excel 12.0;HDR=YES"";"
con.Open sconnect: DoEvents

Dim sqlstr As String

sqlstr = "SELECT e.DAX_ITEMTYPE, e.DAX_WHSE, e.DAX_LOCATION, e.DAX_ITEMID, e.DAX_MODEL, e.location "
sqlstr = sqlstr & "FROM [1.reference$] e "
sqlstr = sqlstr & "WHERE isnull(e.Model) "
' sqlstr = sqlstr & "AND Is not null e.DAX_ITEMTYPE; "
' sqlstr = sqlstr & "GROUP BY e.DAX_ITEMTYPE, e.DAX_WHSE, e.DAX_LOCATION, e.DAX_ITEMID, e.DAX_MODEL, e.location "

rec.Open sqlstr, con, 3, 1: DoEvents

' copy new DAX ITEMID to column H of lookup Ref
With Sheet15
Debug.Print .Range("A" & .Rows.Count).End(xlUp).Offset(1, 0).Address
.Range("A" & .Rows.Count).End(xlUp).Offset(1, 0).CopyFromRecordset rec
End With

Bob Phillips
10-07-2014, 01:03 AM
Can you post the workbook (it is also the data source?)?

Kaniguan1969
10-07-2014, 05:53 PM
SOLVED. THank you xld. I already change the formula. instead of having the result as #N/A, it should be 0. then i change the where clause with Where model = 0.