|
本帖最后由 ykcbf1100 于 2024-1-30 18:45 编辑
代码以附件为准。。。- Sub ykcbf() '//2024.1.30
- fns = [{"蔬菜","水果"}]
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Dim list As New Collection
- For Each sht In Sheets
- If Val(sht.Name) Then
- list.Add sht.Name
- With sht
- fn = .Name
- r1 = .UsedRange.Find("水果批发").Row
- r = .Cells(Rows.Count, 1).End(3).Row
- For x = 1 To UBound(fns)
- If x = 1 Then arr = .Range("a1:e" & r1 - 1)
- If x = 2 Then arr = .Range(.Cells(r1, 1), .Cells(r, 5))
- For i = 4 To UBound(arr)
- If Val(arr(i, 2)) Then
- s = fns(x) & "|" & arr(i, 1) & "|" & arr(i, 5)
- d1(s) = ""
- For j = 2 To 4
- s = fns(x) & "|" & CStr(fn) & "|" & arr(i, 1) & "|" & arr(i, 5) & "|" & arr(4, j)
- d(s) = arr(i, j)
- Next
- End If
- Next
- Next
- End With
- End If
- Next
- ReDim brr(1 To 1, 1 To 100)
- For Each k In list
- m = m + 3
- brr(1, m - 2) = CStr(k)
- brr(1, m - 1) = CStr(k)
- brr(1, m) = CStr(k)
- Next
- For x = 1 To UBound(fns)
- ReDim zrr(1 To 10000, 1 To 2)
- n = 0
- With Sheets(fns(x))
- For Each k In d1.keys
- st = Split(k, "|")
- If st(0) = fns(x) Then
- n = n + 1
- zrr(n, 1) = st(1)
- zrr(n, 2) = st(2)
- End If
- Next
- .UsedRange.Offset(3).Clear
- .[c2:cq2] = ""
- .Rows(2).NumberFormatLocal = "@"
- .[c2:cq2] = brr
- .[a4].Resize(n, 2) = zrr
- arr = .UsedRange
- For i = 4 To UBound(arr)
- For j = 3 To UBound(arr, 2)
- s = fns(x) & "|" & CStr(arr(2, j)) & "|" & arr(i, 1) & "|" & arr(i, 2) & "|" & arr(3, j)
- If d.exists(s) Then
- arr(i, j) = d(s)
- End If
- Next
- Next
- .Rows(2).NumberFormatLocal = "@"
- .UsedRange = arr
- With .UsedRange.Offset(1)
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Next
- Set d = Nothing
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|