1
我有这块VBA代码;在VBA中高亮显示一个单元格
Option Explicit
Function GradeScore(score As Integer) As String
'Calculate grade based on the score given
ThisWorkbook.Activate
If score > 100 Then
ActiveCell.Offset(0, -1).Font.Background = rgbRed
MsgBox "Score can not be more than 100%"
Exit Function
End If
If score < 0 Then
ActiveCell.Offset(0, -1).Font.Background = rgbRed
MsgBox "Score can not be less than 0%"
Exit Function
End If
Select Case score
Case Is >= 75
GradeScore = "A"
Case Is >= 70
GradeScore = "B+"
Case Is >= 60
GradeScore = "B"
Case Is >= 50
GradeScore = "C"
Case Is >= 45
GradeScore = "D"
Case Else
GradeScore = "E"
End Select
End Function
当运行一切正常,除了突出显示单元代码
ActiveCell.Offset(0, -1).Font.Background = rgbRed
我的猜测是,它不挑引用的单元格。我怎样才能做到这一点?
你想成为'字型color'红色或'单元格背景color'红? – harun24hr
@ harun24hr,我想单元格背景颜色为红色,但在我以前的运行中字体都没有改变。 – Amani
您是否将它作为UDF从Excel UI OR函数中调用,以便在宏中调用? – user3598756