|
可以支持 Double 类型的查询:
Sub 库存查询()
Dim lh, sb
Dim lhDouble, sbDouble As Double
' 获取用户输入的查询条件
lh = Sheets("查询表").[c5].Text
sb = Sheets("查询表").[e5].Text
' 尝试将查询条件转换为 Double 类型
On Error Resume Next
lhDouble = CDbl(lh)
sbDouble = CDbl(sb)
On Error GoTo 0
Sheets("查询表").Range("a8:u1000") = ""
Sheets("库存明细表").Range("b5:o5").Copy Sheets("查询表").[a8]
If lh = "" And sb = "" Then
MsgBox "查询条件不能为空!"
Exit Sub
End If
Dim area, mr, area1, rg, rr, n%
mr = Sheets("库存明细表").Cells(Rows.Count, 3).End(xlUp).Row
Set area = Sheets("库存明细表").Range("c6", "c" & mr)
For Each rg In area
' 判断查询条件是否匹配
If (lh = "" Or rg.Value = lh Or rg.Value = lhDouble) And (sb = "" Or rg(1, 2) = sb Or rg(1, 2) = sbDouble) Then
rr = rg.Row
n = n + 1
Sheets("库存明细表").Range("c" & rr, "o" & rr).Copy
Sheets("查询表").Range("b" & 8 + n).PasteSpecial Paste:=xlPasteValues
Sheets("查询表").Range("a" & 8 + n) = n
End If
Next
MsgBox "查询完成!"
End Sub |
|