Sub test()
Dim Ar_in, Arr, Arr1, Brr(), Crr(), xD, T, T1, n&, i&, j&, R&
Set xD = CreateObject("Scripting.Dictionary")
Ar_in = Sheets("輸入").Range("i3:in3")
For sh = 2 To Sheets.Count
With Sheets(sh)
.Range("i3").Resize(1, UBound(Ar_in, 2)) = Ar_in
R = .[b65536].End(3).Row: If R < 2 Then GoTo 95
Arr1 = .Range(.[b5], .[b65536].End(3)): Arr = .Range("i3:in" & UBound(Arr1) + 4)
ReDim Brr(1 To UBound(Arr), 1 To UBound(Arr, 2)) 'IT3:RY
ReDim Preserve Crr(1 To UBound(Arr) - 1, 1 To sh - 1) '輸入的統計
Crr(1, sh - 1) = .Name
For x = 1 To UBound(Arr1)
If Arr1(x, 1) = "" Then GoTo 95
For i = 3 To UBound(Arr)
For j = 1 To UBound(Arr, 2)
T = Arr(i, j): T1 = Arr(1, j)
If T1 = "" Then GoTo 90
If T1 = T Then
Brr(i - 2, j) = 1: n = n + 1
Else
Brr(i - 2, j) = 0
End If
90: Next j
Crr(i - 1, sh - 1) = n: n = 0
Next i
95: Next x
.[it5].Resize(UBound(Brr), UBound(Brr, 2)) = Brr
End With
Next
n = 0
With Sheets(1)
.[i4:r4].NumberFormatLocal = "@"
.[i4].Resize(UBound(Crr), UBound(Crr, 2)) = Crr
With [s5].Resize(UBound(Crr) - 1)
.Formula = "=Sum(i5:r5)": .Value = .Value
End With
With Range([s5], [s4].End(4))
Arr = .Value
.Sort Key1:=.Item(1), Order1:=2, Header:=2
Brr = .Value: .Value = Arr
End With
For i = 1 To UBound(Brr)
T = Brr(i, 1): If Not xD.Exists(T) Then n = n + 1: xD(T) = n
Next
For i = 1 To UBound(Arr): Arr(i, 1) = xD(Arr(i, 1)): Next
.[t5].Resize(UBound(Arr)) = Arr
End With
End Sub作者: oak0723-1 時間: 2022-5-16 16:43
Sub test()
Dim Ar_in, Arr, Arr1, Brr(), Crr(), xD, T, T1, n&, i&, j&, R&, sh%, MaxR&
Set xD = CreateObject("Scripting.Dictionary")
Ar_in = Sheets("輸入").Range("i3:in3")
For sh = 2 To Sheets.Count
With Sheets(sh)
.Range("i3").Resize(1, UBound(Ar_in, 2)) = Ar_in
R = .[b65536].End(3).Row: If R < 2 Then GoTo 95
Arr1 = .Range(.[b5], .[b65536].End(3)): Arr = .Range("i3:in" & UBound(Arr1) + 4)
ReDim Brr(1 To UBound(Arr), 1 To UBound(Arr, 2)) 'IT3:RY
ReDim Preserve Crr(1 To 100000, 1 To sh - 1) '輸入的統計
If MaxR < UBound(Arr) Then MaxR = UBound(Arr)
Crr(1, sh - 1) = .Name
For x = 1 To UBound(Arr1)
If Arr1(x, 1) = "" Then GoTo 95
For i = 3 To UBound(Arr)
For j = 1 To UBound(Arr, 2)
T = Arr(i, j): T1 = Arr(1, j)
If T1 = "" Then GoTo 90
If T1 = T Then
Brr(i - 2, j) = 1: n = n + 1
Else
Brr(i - 2, j) = 0
End If
90: Next j
Crr(i - 1, sh - 1) = n: n = 0
Next i
95: Next x
.[it5].Resize(UBound(Brr), UBound(Brr, 2)) = Brr
End With
Next
n = 0
With Sheets(1)
.[i4:r4].NumberFormatLocal = "@"
.[i4].Resize(MaxR, UBound(Crr, 2)) = Crr
With .[s5].Resize(MaxR - 2)
.Formula = "=Sum(i5:r5)": .Value = .Value
End With
With Range([s5], [s4].End(4))
Arr = .Value
.Sort Key1:=.Item(1), Order1:=2, Header:=2
Brr = .Value: .Value = Arr
End With
For i = 1 To UBound(Brr)
T = Brr(i, 1): If Not xD.Exists(T) Then n = n + 1: xD(T) = n
Next
For i = 1 To UBound(Arr): Arr(i, 1) = xD(Arr(i, 1)): Next
.[t5].Resize(UBound(Arr)) = Arr
End With
End Sub作者: oak0723-1 時間: 2022-5-16 19:49
Sub test()
Dim Ar_in, Arr, Arr1, Brr(), Crr(), xD, T, T1, n&, i&, j&, R&, sh%, MaxR&
Set xD = CreateObject("Scripting.Dictionary")
Tm = Timer
Ar_in = Sheets("輸入").Range("i3:in3")
For sh = 2 To Sheets.Count
With Sheets(sh)
.Range("i3").Resize(1, UBound(Ar_in, 2)) = Ar_in
R = .[b65536].End(3).Row: If R < 2 Then GoTo 95
Arr1 = .Range("b4:b" & R): Arr = .Range("i3:in" & R)
ReDim Brr(1 To UBound(Arr), 1 To UBound(Arr, 2)) 'IT3:RY
ReDim Preserve Crr(1 To 100000, 1 To sh - 1) '輸入的統計
If MaxR < UBound(Arr) Then MaxR = UBound(Arr)
Crr(1, sh - 1) = .Name
For i = 3 To UBound(Arr)
For j = 1 To UBound(Arr, 2)
T = Arr(i, j): T1 = Arr(1, j)
If T1 = "" Then GoTo 90
If T1 = T Then
Brr(i - 2, j) = 1: n = n + 1
Else
Brr(i - 2, j) = 0
End If
90: Next j
Crr(i - 1, sh - 1) = n: n = 0
95: Next i
.[it5].Resize(UBound(Brr), UBound(Brr, 2)) = Brr
End With
Next
n = 0
With Sheets(1)
.[i4:r4].NumberFormatLocal = "@"
.[i4].Resize(MaxR, UBound(Crr, 2)) = Crr
With .[s5].Resize(MaxR - 2)
.Formula = "=Sum(i5:r5)": .Value = .Value
End With
With Range([s5], [s4].End(4))
Arr = .Value
.Sort Key1:=.Item(1), Order1:=2, Header:=2
Brr = .Value: .Value = Arr
End With
For i = 1 To UBound(Brr)
T = Brr(i, 1): If Not xD.Exists(T) Then n = n + 1: xD(T) = n
Next
For i = 1 To UBound(Arr): Arr(i, 1) = xD(Arr(i, 1)): Next
.[t5].Resize(UBound(Arr)) = Arr
End With
MsgBox Timer - Tm
End Sub
[attach]34905[/attach]作者: oak0723-1 時間: 2022-5-17 19:49
Sub test()
TT = Timer
Set sh0 = Sheets("輸入")
ReDim ar(1 To Sheets.Count - 1): w = 1
ReDim ar0(1 To Sheets.Count - 1)
ReDim ar1(1 To Sheets.Count - 1)
sh0.[i5:T1048576].ClearContents
For Each Z In Sheets
If Z.Name <> "輸入" Then
ar(w) = Z.Range("I5:IN" & Z.Cells(Rows.Count, 2).End(3).Row)
ar0(w) = sh0.[I3:IN3]
ReDim ir(1 To UBound(ar(w)), 0)
ar1(w) = ir
If MaxR < UBound(ar(w)) Then MaxR = UBound(ar(w))
w = w + 1
End If
Next
ReDim ar2(1 To MaxR, 0)
For i = 1 To MaxR: ar2(i, 0) = 0: Next
For i = 1 To UBound(ar)
For j = 1 To UBound(ar(i))
For k = 1 To 240
If ar(i)(j, k) = ar0(i)(1, k) Then
ar1(i)(j, 0) = ar1(i)(j, 0) + 1
ar2(j, 0) = ar2(j, 0) + 1
End If
Next
Next
Next
For i = 1 To UBound(ar)
sh0.Cells(5, i + 8).Resize(UBound(ar1(i)), 1) = ar1(i)
Next
sh0.[s5].Resize(UBound(ar2), 1) = ar2
Set d = CreateObject("scripting.dictionary"): d.RemoveAll
For i = 1 To UBound(ar2): d(ar2(i, 0)) = "": Next: d0 = d.keys()
For i = 0 To d.Count - 1
For j = i + 1 To d.Count - 1
If d0(i) < d0(j) Then tp = d0(i): d0(i) = d0(j): d0(j) = tp
Next j: Next i
ReDim d1(0 To d0(0))
For i = 0 To UBound(d0): d1(d0(i)) = i + 1: Next
For i = 1 To UBound(ar2): ar2(i, 0) = d1(ar2(i, 0)): Next
sh0.[T5].Resize(UBound(ar2), 1) = ar2
Sub test()
TT = Timer
Set sh0 = Sheets("輸入")
ReDim ar(1 To Sheets.Count - 1): w = 1
ReDim ar0(1 To Sheets.Count - 1)
ReDim ar1(1 To Sheets.Count - 1)
sh0.[i5:T1048576].ClearContents
For Each Z In Sheets
If Z.Name <> "輸入" Then
ar(w) = Z.Range("I5:IN" & Z.Cells(Rows.Count, 2).End(3).Row)
ar0(w) = sh0.[I3:IN3]
ReDim ir(1 To UBound(ar(w)), 0)
ar1(w) = ir
If MaxR < UBound(ar(w)) Then MaxR = UBound(ar(w))
w = w + 1
End If
Next
ReDim ar2(1 To MaxR, 0)
For i = 1 To MaxR: ar2(i, 0) = 0: Next
For i = 1 To UBound(ar)
For j = 1 To UBound(ar(i))
For k = 1 To 240
If ar0(i)(1, k) <> "" Then
If ar(i)(j, k) = ar0(i)(1, k) Then
ar1(i)(j, 0) = ar1(i)(j, 0) + 1
ar2(j, 0) = ar2(j, 0) + 1
End If
End If
Next
Next
Next
For i = 1 To UBound(ar)
sh0.Cells(5, i + 8).Resize(UBound(ar1(i)), 1) = ar1(i)
Next
sh0.[s5].Resize(UBound(ar2), 1) = ar2
Set d = CreateObject("scripting.dictionary"): d.RemoveAll
For i = 1 To UBound(ar2): d(ar2(i, 0)) = "": Next: d0 = d.keys()
For i = 0 To d.Count - 1
For j = i + 1 To d.Count - 1
If d0(i) < d0(j) Then tp = d0(i): d0(i) = d0(j): d0(j) = tp
Next j: Next i
ReDim d1(0 To d0(0))
For i = 0 To UBound(d0): d1(d0(i)) = i + 1: Next
For i = 1 To UBound(ar2): ar2(i, 0) = d1(ar2(i, 0)): Next
sh0.[T5].Resize(UBound(ar2), 1) = ar2
是這樣嗎?修改如下紅框, 請確認,謝謝
If T1 = "" Then
Brr(i - 2, j) = 0
ElseIf T1 = "0" Then
Brr(i - 2, j) = ""
ElseIf T1 = T Then
Brr(i - 2, j) = 1: n = n + 1
ElseIf T1 <> T Then
Brr(i - 2, j) = 0
End If作者: singo1232001 時間: 2022-5-21 22:19
本帖最後由 singo1232001 於 2022-5-21 22:30 編輯
'若沒問題的話 這個有稍微排版並上註解
Sub test()
TT = Timer
Dim sh0 As Worksheet
Set sh0 = Sheets("輸入")
ReDim ar(1 To Sheets.Count - 1): w = 1 '主陣列 1維+2維多欄 之後混加10張表 總資料
ReDim ar0(1 To Sheets.Count - 1) '次陣列1 1維+2維1欄 10張表 I3:IN3 之後比對用
ReDim ar1(1 To Sheets.Count - 1) '次陣列2 1維+2維1欄 10張表 之後混加各表得分加總
sh0.[i5:T1048576].ClearContents
For Each Z In Sheets
If Z.Name <> "輸入" Then
ar(w) = Z.Range("I5:IN" & Z.Cells(Rows.Count, 2).End(3).Row) '主陣列 混加2維不規則陣列
ar0(w) = sh0.[I3:IN3]
ReDim ir(1 To UBound(ar(w)), 0)
ar1(w) = ir
If MaxR < UBound(ar(w)) Then MaxR = UBound(ar(w))
w = w + 1
End If
Next
ReDim ar2(1 To MaxR, 0) '次陣列3 2維1欄 加總10張表總得分
For i = 1 To MaxR: ar2(i, 0) = 0: Next
For i = 1 To UBound(ar) '根據主陣列與次陣列1比對算分 記錄在次陣列2
For j = 1 To UBound(ar(i)) '10表總分紀錄在次陣列3
For k = 1 To 240
If ar0(i)(1, k) <> "" Then
If ar(i)(j, k) = ar0(i)(1, k) Then
ar1(i)(j, 0) = ar1(i)(j, 0) + 1
ar2(j, 0) = ar2(j, 0) + 1
End If
End If
Next
Next
Next
For i = 1 To UBound(ar) '各表總分依序放入[I5:R1048576]
sh0.Cells(5, i + 8).Resize(UBound(ar1(i)), 1) = ar1(i)
Next
sh0.[s5].Resize(UBound(ar2), 1) = ar2 '全部總分放入[S5:S1048576]
Set d = CreateObject("scripting.dictionary"): d.RemoveAll '去重
For i = 1 To UBound(ar2): d(ar2(i, 0)) = "": Next: d0 = d.keys()
For i = 0 To d.Count - 1 '氣泡排序
For j = i + 1 To d.Count - 1
If d0(i) < d0(j) Then tp = d0(i): d0(i) = d0(j): d0(j) = tp
Next
Next
ReDim d1(0 To d0(0)) '得分轉排名
For i = 0 To UBound(d0): d1(d0(i)) = i + 1: Next
For i = 1 To UBound(ar2): ar2(i, 0) = d1(ar2(i, 0)): Next
sh0.[T5].Resize(UBound(ar2), 1) = ar2 '全部排名放入[T5:T1048576]
Set sh0 = Sheets("輸入")
ReDim ar(1 To Sheets.Count - 1): w = 1 '主陣列 1維+2維多欄 之後混加10張表 總資料
ar0 = sh0.[I3:IN3] '次陣列1 2維1欄 輸入.[I3:IN3] 之後比對用
ReDim ar1(1 To Sheets.Count - 1) '次陣列2 1維+2維1欄 10張表 之後混加各表得分加總
sh0.[i5:T1048576].ClearContents
For Each Z In Sheets
If Z.Name <> "輸入" Then
ar(w) = Z.Range("I5:IN" & Z.Cells(Rows.Count, 2).End(3).Row) '主陣列 混加2維不規則陣列
ReDim ir(1 To UBound(ar(w)), 0)
ar1(w) = ir
If MaxR < UBound(ar(w)) Then MaxR = UBound(ar(w))
w = w + 1
End If
Next
ReDim ar2(1 To MaxR, 0) '次陣列3 2維1欄 加總10張表總得分
For i = 1 To MaxR: ar2(i, 0) = 0: Next
For i = 1 To UBound(ar) '根據主陣列與次陣列1比對算分 記錄在次陣列2
For j = 1 To 240 '10表總分紀錄在次陣列3
If ar0(1, j) <> "" Then '為空不算
For k = 1 To UBound(ar(i))
If ar(i)(k, j) = ar0(1, j) Then '輸入與資料判斷相同
ar1(i)(k, 0) = ar1(i)(k, 0) + 1 '各表 該列+1分
ar2(k, 0) = ar2(k, 0) + 1 '總表 該列+1分
End If
Next
End If
Next
Next
For i = 1 To UBound(ar) '各表總分依序放入[I5:R1048576]
sh0.Cells(5, i + 8).Resize(UBound(ar1(i)), 1) = ar1(i)
Next
sh0.[s5].Resize(UBound(ar2), 1) = ar2 '全部總分放入[S5:S1048576]
Set d = CreateObject("scripting.dictionary"): d.RemoveAll '去重
For i = 1 To UBound(ar2): d(ar2(i, 0)) = "": Next: d0 = d.keys()
For i = 0 To d.Count - 1 '氣泡排序
For j = i + 1 To d.Count - 1
If d0(i) < d0(j) Then tp = d0(i): d0(i) = d0(j): d0(j) = tp
Next
Next
ReDim d1(0 To d0(0)) '得分轉排名
For i = 0 To UBound(d0): d1(d0(i)) = i + 1: Next '創d1排名對照表陣列
For i = 1 To UBound(ar2): ar2(i, 0) = d1(ar2(i, 0)): Next '依對照表index修改
sh0.[T5].Resize(UBound(ar2), 1) = ar2 '全部排名放入[T5:T1048576]
Set sh0 = Sheets("輸入")
ReDim ar(1 To Sheets.Count - 1): w = 1 '主陣列 1維+2維多欄 之後混加10張表 總資料
ar0 = sh0.[I3:IN3] '次陣列1 2維1欄 輸入.[I3:IN3] 之後比對用
ReDim ar1(1 To Sheets.Count - 1) '次陣列2 1維+2維1欄 10張表 之後混加各表得分加總
sh0.[i5:T1048576].ClearContents
For Each Z In Sheets
If Z.Name <> "輸入" Then
ar(w) = Z.Range("I5:IN" & Z.Cells(Rows.Count, 2).End(3).Row) '主陣列 混加2維不規則陣列
ReDim ir(1 To UBound(ar(w)), 0)
ar1(w) = ir
If MaxR < UBound(ar(w)) Then MaxR = UBound(ar(w))
w = w + 1
End If
Next
ReDim ar2(1 To MaxR, 0) '次陣列3 2維1欄 加總10張表總得分
For i = 1 To MaxR: ar2(i, 0) = 0: Next
For i = 1 To UBound(ar) '根據主陣列與次陣列1比對算分 記錄在次陣列2
For j = 1 To 240 '10表總分紀錄在次陣列3
If ar0(1, j) <> "" Then '為空不算
For k = 1 To UBound(ar(i))
If ar(i)(k, j) = ar0(1, j) Then '輸入與資料判斷相同
ar1(i)(k, 0) = ar1(i)(k, 0) + 1 '各表 該列+1分
ar2(k, 0) = ar2(k, 0) + 1 '總表 該列+1分
If ar(i)(k, j) = "" And ar0(1, j) = 0 Then
ar1(i)(k, 0) = ar1(i)(k, 0) - 1 '遇到0="" 把分數扣回來-1
ar2(k, 0) = ar2(k, 0) - 1 '遇到0="" 把分數扣回來-1
End If
End If
Next
End If
Next
Next
For i = 1 To UBound(ar) '各表總分依序放入[I5:R1048576]
sh0.Cells(5, i + 8).Resize(UBound(ar1(i)), 1) = ar1(i)
Next
sh0.[s5].Resize(UBound(ar2), 1) = ar2 '全部總分放入[S5:S1048576]
Set d = CreateObject("scripting.dictionary"): d.RemoveAll '去重
For i = 1 To UBound(ar2): d(ar2(i, 0)) = "": Next: d0 = d.keys()
For i = 0 To d.Count - 1 '氣泡排序
For j = i + 1 To d.Count - 1
If d0(i) < d0(j) Then tp = d0(i): d0(i) = d0(j): d0(j) = tp
Next
Next
ReDim d1(0 To d0(0)) '得分轉排名
For i = 0 To UBound(d0): d1(d0(i)) = i + 1: Next '創d1排名對照表陣列
For i = 1 To UBound(ar2): ar2(i, 0) = d1(ar2(i, 0)): Next '依對照表index修改
sh0.[T5].Resize(UBound(ar2), 1) = ar2 '全部排名放入[T5:T1048576]
Set sh0 = Sheets("輸入")
ReDim ar(1 To Sheets.Count - 1): w = 1 '主陣列 1維+2維多欄 之後混加10張表 總資料
ar0 = sh0.[I3:IN3] '次陣列0 2維1欄 輸入.[I3:IN3] 之後比對用
'ReDim ar1(1 To Sheets.Count - 1) '次陣列1 1維+2維1欄 10張表 之後混加各表得分加總
sh0.[i5:T1048576].ClearContents
For Each Z In Sheets
If Z.Name <> "輸入" Then
ar(w) = Z.Range("I5:IN" & Z.Cells(Rows.Count, 2).End(3).Row) '主陣列 混加2維不規則陣列
' ReDim ir(1 To UBound(ar(w)), 0)
' ar1(w) = ir
If MaxR < UBound(ar(w)) Then MaxR = UBound(ar(w))
w = w + 1
End If
Next
ReDim ar2(1 To MaxR, 0) As Integer '次陣列2 2維1欄 加總10張表總得分
'For i = 1 To MaxR: ar2(i, 0) = 0: Next
For i = 1 To UBound(ar) '根據主陣列與次陣列1比對算分 記錄在次陣列2
For j = 1 To 240 '10表總分紀錄在次陣列3
If ar0(1, j) <> "" Then '為空不算
For k = 1 To UBound(ar(i))
If ar(i)(k, j) = ar0(1, j) Then '輸入與資料判斷相同
' ar1(i)(k, 0) = ar1(i)(k, 0) + 1 '各表 該列+1分
ar2(k, 0) = ar2(k, 0) + 1 '總表 該列+1分
If ar(i)(k, j) = "" Then
If ar0(1, j) = 0 Then
'ar1(i)(k, 0) = ar1(i)(k, 0) - 1 ' '遇到0="" 把分數扣回來-1
ar2(k, 0) = ar2(k, 0) - 1 '遇到0="" 把分數扣回來-1
End If
End If
End If
Next
End If
Next
Next
'For i = 1 To UBound(ar) '各表總分依序放入[I5:R1048576]
'sh0.Cells(5, i + 8).Resize(UBound(ar1(i)), 1) = ar1(i)
'Next
sh0.[s5].Resize(UBound(ar2), 1) = ar2 '全部總分放入[S5:S1048576]
Set d = CreateObject("scripting.dictionary"): d.RemoveAll '去重
For i = 1 To UBound(ar2): d(ar2(i, 0)) = "": Next
d0 = d.keys() '次陣列3
For i = 0 To d.Count - 1 '次陣列3 氣泡排序
For j = i + 1 To d.Count - 1
If d0(i) < d0(j) Then tp = d0(i): d0(i) = d0(j): d0(j) = tp
Next
Next
ReDim d1(0 To d0(0)) '得分轉排名
For i = 0 To UBound(d0): d1(d0(i)) = i + 1: Next '創d1排名對照表陣列
For i = 1 To UBound(ar2): ar2(i, 0) = d1(ar2(i, 0)): Next '依對照表index修改次陣列3
sh0.[T5].Resize(UBound(ar2), 1) = ar2 '全部排名放入[T5:T1048576]