我对 excel vba 很陌生,这就是我为满足以下条件而写的
- sumA 大于 sumB 或 sumC 然后 "G"
- sumB 大于 sumA 或 sumC 然后 "Y"
- sumC 大于 sumA 或 sumB 然后 "R"
在 gr,yr,rr 单元格范围内是我将手动输入的数字。
Dim gr As Range
Dim yr As Range
Dim rr As Range
Dim gr1 As Long
Dim yr1 As Long
Dim rr1 As Long
Dim overallrisk As Range
Set overallrisk = Sheets("Dashboard").Range("C24")
Set gr = Sheets("Dashboard").Range("C30:C32").Range("C33:C35").Range("D33:D35")
Set yr = Sheets("Dashboard").Range("C27:C29").Range("D30:D32").Range("E33:E35")
Set rr = Sheets("Dashboard").Range("D27:D29").Range("E27:E29").Range("E30:E32")
gr1 = Application.WorksheetFunction.Sum(gr)
yr1 = Application.WorksheetFunction.Sum(yr)
rr1 = Application.WorksheetFunction.Sum(rr)
If gr1 > yr1 Or rr1 Then
overallrisk = "G"
ElseIf yr1 > gr1 Or rr1 Then
overallrisk = "Y"
ElseIf rr1 > yr1 Or gr1 Then
overallrisk = "R"
End If
我没有收到任何错误,所以我认为它会起作用,但是即使我在单元格范围内输入了数字,“overallrisk”单元格仍然是空白的。
谢谢!