|
楼主 |
发表于 2018-3-20 23:38
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 chengshanming 于 2018-3-21 08:24 编辑
一把小刀闯天下 发表于 2018-3-20 17:27
'可以是全部条件,你这7个条件当然也是可以用的
Option Explicit
小刀闯天下大师好!你的这中方法的代码可以应用于一个工作薄多张格式相同的工作表的这中情况吗?我试了一下,好像只能取到一张表的明细。
- Sub zz()
- Dim j, i, arr, brr, n, first, last, cond
- Dim sh As Worksheet
- [a6].Resize(Cells(Rows.Count, "a").End(xlUp).Row, UBound(UsedRange.Value, 2)).ClearContents
- For Each sh In ThisWorkbook.Sheets
- With sh
- arr = .Range("a2:r" & .Cells(Rows.Count, "a").End(xlUp).Row)
- End With
- ReDim brr(1 To UBound(arr, 1), 1 To UBound(arr, 2))
- With Sheets("查询")
- first = .[c1]: last = .[c2]: cond = .[a4:r4]
- For i = 1 To UBound(arr, 1)
- If arr(i, 1) <= last And arr(i, 1) >= first Then
- For j = 1 To UBound(cond, 2)
- If Len(cond(1, j)) > 0 Then
- If InStr(arr(i, j), cond(1, j)) = 0 Then Exit For
- End If
- Next
- If j = UBound(cond, 2) + 1 Then
- n = n + 1
- For j = 1 To UBound(cond, 2): brr(n, j) = arr(i, j): Next
- End If
- End If
- Next
- If n > 0 Then .Range("a" & UsedRange.Rows.Count + 1).Resize(n, UBound(brr, 2)) = brr
- End With
- Next
- End Sub
复制代码
小刀闯天下大师好!你的这中方法的代码可以应用于一个工作薄多张格式相同的工作表的这中情况吗?我试了一下,好像只能取到一张表的明细。 |
|