|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 会员消费查询()
Dim d, i%, arr, brr()
Dim rn As Range
Set d = CreateObject("scripting.dictionary")
arr = Sheets("明细表").Range("a1").CurrentRegion
With Sheets("查询")
mc = .[b2]
zd = .[c2]
If mc = "" Then MsgBox "请选择查询项目!": End
If zd = "" Then MsgBox "请输入关键字!": End
Set rn = Sheets("明细表").Rows(1).Find(mc, , , , , , 1)
If rn Is Nothing Then MsgBox "明细表中没有" & mc & "列字段": End
y = rn.Column
ReDim brr(1 To UBound(arr), 1 To 4)
For i = 2 To UBound(arr)
If Trim(arr(i, y)) <> "" Then
If InStr(arr(i, y), zd) > 0 Then
t = d(Trim(arr(i, y)))
If t = "" Then
k = k + 1
d(Trim(arr(i, y))) = k
t = k
For j = 2 To 4
brr(k, j - 1) = arr(i, j)
Next j
End If
brr(t, 4) = brr(t, 4) + arr(i, 5)
End If
End If
Next i
If k = "" Then MsgBox "没有符合条件的数据!": End
.UsedRange.Offset(4) = Empty
.[a5].Resize(k, UBound(brr, 2)) = brr
End With
End Sub
|
|