高亮显示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
我的猜测是,它不会select引用的单元格。 我怎样才能做到这一点?
尝试这个 –
ActiveCell.Offset(0, -1).Interior.Color = rgbRed