|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 清空()
- Sheet1.Range("C8").Resize(1000, 14).ClearContents
- Sheet1.Range("C8:O1000").Borders.LineStyle = xlNone
- End Sub
- Sub 模糊筛选()
- Dim m As Boolean
- Dim my()
- Dim arr()
- Dim sht As Worksheet
- For Each sht In Sheets
- If sht.Name <> "查询" Then
- If sht.Index > 1 Then
- temp = sht.UsedRange
- 表名 = sht.Name
- For i = 2 To UBound(temp)
- If temp(i, 1) <> "" Then
- b = b + 1
- ReDim Preserve my(1 To 14, 1 To b)
- my(14, b) = 表名
- For j = 1 To UBound(temp, 2)
- my(j, b) = temp(i, j)
- Next
- End If
- Next
- End If
- End If
- Next
- ReDim arr(1 To b, 1 To 14)
- For i = 1 To b
- For j = 1 To 14
- arr(i, j) = my(j, i)
- Next
- Next
- 工作表名称 = Sheet1.Range("B5").Value
- 记录类别 = Sheet1.Range("C5").Value
- 供应商名称 = Sheet1.Range("E5").Value
- 物资代码 = Sheet1.Range("F5").Value
- 物资名称 = Sheet1.Range("G5").Value
- 物资规格 = Sheet1.Range("H5").Value
- 单位 = Sheet1.Range("I5").Value
- 数量 = Sheet1.Range("J5").Value
- 单价 = Sheet1.Range("K5").Value
- 金额 = Sheet1.Range("L5").Value
- 使用部门 = Sheet1.Range("M5").Value
- 部门签收 = Sheet1.Range("N5").Value
- 备注 = Sheet1.Range("O5").Value
- If Trim(CStr(Sheet1.Range("D5").Value)) = "" Then
- 起始日期 = CDate("1900-01-01")
- Else
- 起始日期 = CDate(Trim(CStr(Sheet1.Range("D5").Value)))
- End If
- If Trim(CStr(Sheet1.Range("D6").Value)) = "" Then
- 结束日期 = CDate("2100-12-31")
- Else
- 结束日期 = CDate(Trim(CStr(Sheet1.Range("D6").Value)))
- End If
- ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2) - 1)
- For i = 2 To UBound(arr)
- If arr(i, 1) <> "" Then
- m = True
- If CDate(arr(i, 2)) >= 起始日期 And CDate(arr(i, 2)) <= 结束日期 Then
- If 工作表名称 <> "" And (InStr(arr(i, 14), 工作表名称) = 0) Then
- m = False
- End If
- If 记录类别 <> "" And (InStr(arr(i, 1), 记录类别) = 0) Then
- m = False
- End If
-
- If 供应商名称 <> "" And (InStr(arr(i, 3), 供应商名称) = 0) Then
- m = False
- End If
- If 物资代码 <> "" And (InStr(arr(i, 4), 物资代码) = 0) Then
- m = False
- End If
- If 物资名称 <> "" And (InStr(arr(i, 5), 物资名称) = 0) Then
- m = False
- End If
- If 物资规格 <> "" And (InStr(arr(i, 6), 物资规格) = 0) Then
- m = False
- End If
- If 单位 <> "" And (InStr(arr(i, 7), 单位) = 0) Then
- m = False
- End If
- If 数量 <> "" And (InStr(arr(i, 8), 数量) = 0) Then
- m = False
- End If
- If 单价 <> "" And (InStr(arr(i, 9), 单价) = 0) Then
- m = False
- End If
- If 金额 <> "" And (InStr(arr(i, 10), 金额) = 0) Then
- m = False
- End If
- If 使用部门 <> "" And (InStr(arr(i, 11), 使用部门) = 0) Then
- m = False
- End If
- If 部门签收 <> "" And (InStr(arr(i, 12), 部门签收) = 0) Then
- m = False
- End If
- If 备注 <> "" And (InStr(arr(i, 13), 备注) = 0) Then
- m = False
- End If
-
- If m = True Then
- k = k + 1
- For j = 1 To UBound(arr, 2) - 1
- brr(k, j) = arr(i, j)
- Next
- End If
- End If
- End If
- Next
- Call 清空
- If k > 0 Then
- Sheet1.Range("C8").Resize(k, UBound(brr, 2)) = brr
- Sheet1.Range("C8:O" & CStr(k + 7)).Borders.LineStyle = xlContinuous
- Else
- MsgBox "查询无数据"
- End If
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|