gpt4 book ai didi

excel - 验证单元格并获得成绩

转载 作者:行者123 更新时间:2023-12-04 22:03:16 25 4
gpt4 key购买 nike

这是我的要求。我有一张表,其中 B 列有标记。根据标记并单击按钮,我正在尝试获得成绩并根据成绩为单元格着色。以下是我编写的代码,但这没有成功。请帮忙

Sub SetGrade()
Dim r As Integer
Dim Score As Double

For r = 2 To 20
Score = Cells(r, 2).Value

If Score >= 90 And Score <= 100 Then
ActiveCell(1, 2).Value = "A"
ActiveCell(1, 2).Interior.ColorIndex = 4
ActiveCell(1, 2).HorizontalAlignment = xlCenter
ElseIf Score >= 75 And Score <= 90 Then
ActiveCell(1, 2).Value = "B"
ActiveCell(1, 2).Interior.ColorIndex = 46
ActiveCell(1, 2).HorizontalAlignment = xlLeft
End If
Next r
End Sub

最佳答案

我认为你真正需要做的是像这样摆脱 activecell:

Sub SetGrade()
Dim r As Integer
Dim Score As Double

For r = 2 To 20

Score = Cells(r, 2).Value

If Score >= 90 And Score <= 100 Then

Cells(r, 3).Value = "A"
Cells(r, 3).Interior.ColorIndex = 4
Cells(r, 3).HorizontalAlignment = xlCenter

ElseIf Score >= 75 And Score <= 90 Then

Cells(r, 3).Value = "B"
Cells(r, 3).Interior.ColorIndex = 46
Cells(r, 3).HorizontalAlignment = xlLeft

End If

Next r

End Sub

关于excel - 验证单元格并获得成绩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30349633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com