|
楼主给的数据不严格,测试比较难,不过我大概了解了下,觉得还是用字典应该可以解决,sql模式不需要数据库也可以,或者存入access数据库再来计算也行,excel的sql语句也支持Sub 模糊查询()
'''''''参考qingc0221老师的代码修改而来,比较懒。。..............
Dim LastRow As Long
Dim cnn As Object
Dim Str As String, Sql As String
Set cnn = CreateObject("ADODB.Connection")
Sheets("学员信息查询").Activate
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Range(Rows(3), Rows(LastRow + 1)).ClearContents
Str = Cells(1, "J") '''''这里是查询关键词,J是列1是行,1行J列
If Str = "" Then
MsgBox "查询条件不能为空"
Exit Sub
End If
If Application.Version = "11.0" Then
cnn.Open "Provider=Microsoft.jet.oledb.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName
Else
cnn.Open "Provider=Microsoft.ace.oledb.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
End If
Sql = "select * from [DATA$] where 姓名 like '%" & Str & "%'"
Range("A3").CopyFromRecordset cnn.Execute(Sql)
End Sub
|
|