|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test0() '为何 及格率、优秀率为 100% ?
- Dim Data, Result(), Dict As Object, strKey As String, ss As String
- Dim i As Long, j As Long, Cnt As Long, posRow As Long, posCol As Long
- Dim pas As Double, exc As Double, high As Double, low As Double, Total As Double
-
- high = 660
- low = 600
- posCol = 13
- Set Dict = CreateObject("Scripting.Dictionary")
- Dict.Add "Higher", posCol
- For i = high - 10 To 600 Step -10
- posCol = posCol + 1
- Dict.Add i, posCol
- Next
- ' For j = i - 10 To low Step -20
- ' posCol = posCol + 1
- ' Dict.Add j, posCol
- ' Dict.Add j + 10, posCol
- ' Next
- Dict.Add "Lower", posCol + 1
- ReDim Result(1 To 234, 1 To posCol + 1)
-
- Sheet9.Activate
- If Len(Range("G2").Value) Then exc = Range("G2").Value Else exc = 560
- If Len(Range("I2").Value) Then pas = Range("I2").Value Else pas = 420
-
- Data = Sheet1.Range("A4:L" & Sheet1.Range("A" & Rows.Count).End(xlUp).Row)
- For i = 1 To UBound(Data)
- strKey = Trim(Data(i, 1))
-
- If Dict.Exists(strKey) Then
- posRow = Dict(strKey)
- Else
- Cnt = Cnt + 1
- Result(Cnt, 1) = strKey
- Result(Cnt, 11) = 0
- Result(Cnt, 12) = 10 ^ 6
- Dict.Add strKey, Cnt
- posRow = Cnt
- End If
-
- ' If Trim(Data(i, 1)) <> strKey Then '数据有序时,这快一丁点儿 约 0.01s
- ' Cnt = Cnt + 1
- ' Result(Cnt, 1) = strKey
- ' Result(Cnt, 11) = 0
- ' Result(Cnt, 12) = 10 ^ 6
- ' strKey = Trim(Data(i, 1))
- ' posRow = Cnt
- ' End If
- Result(posRow, 2) = Result(posRow, 2) + 1
-
- If Len(Data(i, 12)) Then
- Total = Val(Data(i, 12))
- Result(posRow, 3) = Result(posRow, 3) + 1
- Result(posRow, 5) = Result(posRow, 5) + Total
- If Total >= exc Then Result(posRow, 7) = Result(posRow, 7) + 1
- If Total >= pas Then Result(posRow, 9) = Result(posRow, 9) + 1
- If Total > Result(posRow, 11) Then Result(posRow, 11) = Total
- If Total < Result(posRow, 12) Then Result(posRow, 12) = Total
- If Total < low Then
- posCol = Dict("Lower")
- Result(posRow, posCol) = Result(posRow, posCol) + 1
- Else
- If Total < high Then j = Dict(Int(Total / 10) * 10) Else j = Dict("Higher")
- For posCol = j To UBound(Result, 2) - 1
- Result(posRow, posCol) = Result(posRow, posCol) + 1
- Next
- End If
- End If
- Next
-
- For i = 1 To Cnt
- For j = 4 To 10 Step 2
- Result(i, j) = Result(i, j - 1) / Result(i, 3 + (j = 4))
- Next
- Next
-
- ActiveSheet.UsedRange.Offset(3).ClearContents
- Range("A4").Resize(Cnt, UBound(Result, 2)) = Result
-
- Set Dict = Nothing
- Beep
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|