|
- Option Explicit
- Sub Demo2()
- Dim oDicCJ, oDicJP, oDicNL, rngData2 As Range
- Dim i As Long, j As Long, k As Long, sKey As String
- Dim arrData, arrData2, arrData3, aMin, aMax, aIdx
- Dim oSht1 As Worksheet, oSht2 As Worksheet
- Const COLCNT = 13
- Const SUBJECT = "语数英物历化生政地"
- aMin = Split("60 20 40 10 30 10 30 30 30")
- aMax = Split("85 50 65 30 50 30 45 50 51")
- aIdx = Split("3 4 5 6 13 7 9 11 14")
- Set oSht1 = ThisWorkbook.Sheets("1")
- Set oSht2 = ThisWorkbook.Sheets("上次成绩")
- Set oDicCJ = CreateObject("scripting.dictionary")
- Set oDicJP = CreateObject("scripting.dictionary")
- Set oDicNL = CreateObject("scripting.dictionary")
- ' testing ============
- oSht1.Range("C2:M7").Interior.Color = xlNone
- oSht1.Range("C2:M7").Interior.Color = xlNone
- '============
- arrData3 = oSht2.Range("V1").CurrentRegion.Value
- For i = LBound(arrData3) + 1 To UBound(arrData3)
- oDicNL(arrData3(i, 1)) = i
- Next i
- arrData2 = oSht2.Range("AB1").CurrentRegion.Value
- For i = LBound(arrData2) + 1 To UBound(arrData2)
- oDicCJ(arrData2(i, 1)) = ""
- Next i
- Set rngData2 = oSht2.Range("A1").CurrentRegion
- arrData2 = rngData2.Value
- For i = LBound(arrData2) + 1 To UBound(arrData2)
- oDicCJ(arrData2(i, 1)) = i
- Next i
- Dim rngRed As Range, rRow As Range, iR As Long, sSub, iLoc
- Set rngData2 = oSht1.Range("A1").CurrentRegion
- arrData = rngData2.Value
- For i = 2 To UBound(arrData)
- sKey = arrData(i, 2)
- If Len(sKey) > 0 Then
- If oDicCJ.exists(sKey) Then
- iR = oDicCJ(sKey)
- arrData(i, 3) = arrData2(iR, 2) ' 班级
- arrData(i, 4) = arrData2(iR, 3) ' 语文
- arrData(i, 5) = arrData2(iR, 4) ' 数学
- If oDicJP.exists(sKey) Then
- arrData(i, 6) = ""
- Else
- arrData(i, 6) = arrData2(iR, 5) ' 英语
- End If
- For j = 3 To 6
- If Len(arrData(i, j)) = 0 Then
- arrData(i, j) = Application.RandBetween(aMin(iLoc - 3), aMax(iLoc - 3))
- Set rngRed = MergeRng(rngRed, oSht1.Cells(i, j))
- End If
- Next
- arrData(i, 13) = arrData2(iR, 16) ' 组合
- If Len(arrData(i, 13)) = 0 Then
- Set rngRed = MergeRng(rngRed, oSht1.Cells(i, 7).Resize(1, 7))
- Else
- For k = 1 To Len(arrData(i, 13))
- sSub = Mid(arrData(i, 13), k, 1)
- iLoc = InStr(SUBJECT, sSub)
- If iLoc > 0 Then
- If Len(arrData2(iR, aIdx(iLoc - 1))) = 0 Then
- arrData(i, iLoc + 3) = Application.RandBetween(aMin(iLoc - 1), aMax(iLoc - 1))
- Set rngRed = MergeRng(rngRed, oSht1.Cells(i, iLoc + 3))
- Else
- arrData(i, iLoc + 3) = arrData2(iR, aIdx(iLoc - 1))
- End If
- End If
- Next
- End If
- Else
- If oDicNL.exists(sKey) Then
- iR = oDicNL(sKey)
- arrData(i, 3) = arrData3(iR, 3) ' 班级
- For j = 3 To 6
- If Len(arrData(i, j)) = 0 Then
- arrData(i, j) = Application.RandBetween(aMin(iLoc - 3), aMax(iLoc - 3))
- Set rngRed = MergeRng(rngRed, oSht1.Cells(i, j))
- End If
- Next
- arrData(i, 13) = arrData3(iR, 2) ' 组合
- If Len(arrData(i, 13)) = 0 Then
- Set rngRed = MergeRng(rngRed, oSht1.Cells(i, 7).Resize(1, 7))
- Else
- For k = 1 To Len(arrData(i, 13))
- sSub = Mid(arrData(i, 13), k, 1)
- iLoc = InStr(SUBJECT, sSub)
- If iLoc > 0 Then
- If Len(arrData(i, iLoc + 3)) = 0 Then
- arrData(i, iLoc + 3) = Application.RandBetween(aMin(iLoc - 1), aMax(iLoc - 1))
- Set rngRed = MergeRng(rngRed, oSht1.Cells(i, iLoc + 3))
- End If
- End If
- Next
- End If
- Else
- Set rngRed = MergeRng(rngRed, oSht1.Cells(i, 3).Resize(1, COLCNT - 2))
- End If
- End If
- End If
- Next
- rngData2.Value = arrData
- If Not rngRed Is Nothing Then
- rngRed.Interior.Color = vbRed
- End If
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|