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