|
楼主 |
发表于 2022-12-9 14:23
|
显示全部楼层
现将老师代码及注释整理如下:
- Sub 填充颜色字体()
- Dim arr, i&, j&, sScore As Single, rng As Range
- Application.ScreenUpdating = False '应用程序屏幕更新 = 没有
- With Sheets("sheet1")
- .[f2:m100].Interior.ColorIndex = 0 '填充颜色清0
- .[f2:m100].Font.ColorIndex = 0 '字体颜色清零
- .[f2:m100].Font.Bold = False '字体加粗清零
- arr = .Range(.Cells(Rows.Count, "M").End(xlUp), "F1")
-
- Set rng = .Range(.Cells(Rows.Count, "M").End(xlUp), "F1")
- For i = 2 To 5 'ubound(arr,2)
- For j = 2 To UBound(arr) '循环从第2行开始
- sScore = .Cells(j, "m") '改成 M 列,每行与其的值,不是固定数值,[m3],[m4],[m5]....
- If arr(j, i) >= sScore Then '大于等于分数(m列)
- Select Case rng.Cells(1, i).Value
- Case Is = "第三次模拟成绩"
- rng.Cells(j, 2).Font.Color = vbRed
- rng.Cells(j, 2).Font.Bold = True
- rng.Cells(j, 2).Interior.Color = RGB(240, 165, 120)
- Case Is = "第二次模拟成绩"
- rng.Cells(j, 3).Font.Color = vbRed
- rng.Cells(j, 3).Font.Bold = False
- rng.Cells(j, 3).Interior.Color = RGB(240, 175, 135)
- Case Is = "第一次模拟成绩"
- rng.Cells(j, 4).Font.Color = vbRed
- rng.Cells(j, 4).Font.Bold = False
- rng.Cells(j, 4).Interior.Color = RGB(240, 185, 150)
- Case Is = "期中模拟成绩"
- rng.Cells(j, 5).Font.Color = vbRed
- rng.Cells(j, 5).Font.Bold = False
- rng.Cells(j, 5).Interior.Color = xlNone 'xlNone 无填充色
- End Select
-
- End If
- Next j
- Next i
- End With
- '--------------以下为表头字体颜色---------------------------
- 'With Sheet1.Range("f1:m1")
- ' .Font.Name = "宋体"
- ' .Font.Size = 12
- ' .Columns.AutoFit
- 'End With
- '--------------以下为区域边框线条字体等样式--------------
- 'With Sheet1.[f2].CurrentRegion.Offset(1)
- '.Font.Name = "arial"
- '.Font.Size = 9
- '.Borders.LineStyle = xlContinuous
- '.HorizontalAlignment = xlCenter
- 'End With
- '-------------------------------------------------------------------
- Application.ScreenUpdating = True '应用程序屏幕更新 = 是的
-
- End Sub
复制代码
|
|