通过VBA excel使用IsNumeric SQL查询

时间:2017-10-30 05:52:59

标签: vba excel-vba excel

请在我的下面的VBA代码中找到我只想过滤下面数据的数值数据。但我没有得到所需的输出。请建议我。

enter image description here

Sub SQL()

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

strFile = ThisWorkbook.FullName
strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFile _
& ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";"

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open strCon

strSQL = "SELECT [Sheet5$].[Sr], [Ch] FROM [Sheet5$] WHERE IsNumeric([Sheet5$].[ch]) = 1"

rs.Open strSQL, cn

Sheet5.Range("D1").CopyFromRecordset rs

'Debug.Print rs.GetString

End Sub

1 个答案:

答案 0 :(得分:0)

放弃=1

strSQL = "SELECT [Sheet5$].[Sr], [Ch] FROM [Sheet5$] WHERE IsNumeric([Sheet5$].[ch])"