|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码如下。。。
Sub test2() '2024-9-27修改 'instr的方法
Application.ScreenUpdating = False
For Each sht In ThisWorkbook.Sheets
r = 0: m = 0: x = 0
For i = 1 To 16
r_1 = sht.Cells(Rows.Count, i + 3).End(3).Row
r = Application.Max(r, r_1)
Next
arr = sht.Range(sht.[a3], sht.Cells(r + 1, "s"))
c = sht.Cells(1, sht.Columns.Count).End(1).Column
brr = sht.Range(sht.[t1], sht.Cells(1, c))
ReDim crr(1 To UBound(arr) + 1, 1 To UBound(brr, 2) + 1)
For j = 1 To UBound(brr, 2) Step 2
If j < 72 Then
n = 2
crr(n, j) = 1
For i = 2 To UBound(arr)
If arr(i, 4) <> "" Then
If InStr(brr(1, j), arr(i, 4)) Then
n = n + 1
crr(n, j) = arr(i, 1)
m = Application.Max(m, n)
If n = 1 Then crr(n, j + 1) = Empty Else crr(n, j + 1) = crr(n, j) - crr(n - 1, j) - 1
End If
ElseIf i = UBound(arr) Then
n = n + 1
crr(n, j) = arr(i, 1)
m = Application.Max(m, n)
If n = 1 Then crr(n, j + 1) = Empty Else crr(n, j + 1) = crr(n, j) - crr(n - 1, j) - 1
End If
Next
crr(1, j + 1) = crr(n, j + 1)
Else
n = 2: x = x + 1
crr(n, j) = 1
For i = 2 To UBound(arr)
If brr(1, j) = CStr(arr(i, x + 4)) Then
n = n + 1
crr(n, j) = arr(i, 1)
m = Application.Max(m, n)
If n = 1 Then crr(n, j + 1) = Empty Else crr(n, j + 1) = crr(n, j) - crr(n - 1, j) - 1
End If
If i = UBound(arr) Then
n = n + 1
crr(n, j) = arr(i, 1)
m = Application.Max(m, n)
crr(n, j + 1) = crr(n, j) - crr(n - 1, j) - 1
End If
Next
End If
crr(1, j + 1) = crr(n, j + 1)
Next
sht.[t2].Resize(sht.[t2].CurrentRegion.Rows.Count, UBound(crr, 2)).ClearContents
sht.Cells(2, "t").Resize(m, UBound(crr, 2)) = crr
Next
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
2
查看全部评分
-
|