我正在制作一份发送给代理机构的表格,对于这张特定的表格,所有总数都假设彼此相等。我使用If语句来检查总计是否都相等但是当使用Or来连接变量时,在IF语句中,总计中的一个错误会使所有字段变为红色,因此用户无法快速找到他们的错误。使用And连接变量也会导致错误,因为如果2个单独的总计中存在错误,则根本不会显示错误。当按下一个按钮时,我希望程序比较所有总数,并且仅使那些与其他总数不匹配的那些红色,无论如何我还能做到这一点吗?它更多的是逻辑问题,但这是我的代码:
Sheets("Initiated Proceedings").Select
Sheet3.Unprotect
DisputantTotal = Range("I19").Value
DisputantFrequency = Range("I24").Value
GenderTotal = Range("I31").Value
AgeTotal = Range("I39").Value
EthnicityTotal = Range("I50").Value
LanguageTotal = Range("I65").Value
IncomeTotal = Range("I73").Value
DisabilityTotal = Range("I79").Value
HomelessTotal = Range("I85").Value
If DisputantTotal <> DisputantFrequency Or DisputantTotal <> GenderTotal Or DisputantTotal <> AgeTotal Or DisputantTotal <> EthnicityTotal Or DisputantTotal <> LanguageTotal Or DisputantTotal <> IncomeTotal Or DisputantTotal <> HomelessTotal Or DisputantTotal = 0 Then
Range("I19").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Else
Range("I19").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
End If
If DisputantTotal <> DisputantFrequency Or DisputantFrequency <> GenderTotal Or DisputantFrequency <> AgeTotal Or DisputantFrequency <> EthnicityTotal Or DisputantFrequency <> LanguageTotal Or DisputantFrequency <> IncomeTotal Or DisputantFrequency <> HomelessTotal Or DisputantFrequency = 0 Then
Range("I24").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Else
Range("I24").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
End If
If DisputantTotal <> GenderTotal Or DisputantFrequency <> GenderTotal Or GenderTotal <> AgeTotal Or GenderTotal <> EthnicityTotal Or GenderTotal <> LanguageTotal Or GenderTotal <> IncomeTotal Or GenderTotal <> HomelessTotal Or GenderTotal = 0 Then
Range("I31").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Else
Range("I31").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
End If
If DisputantTotal <> AgeTotal Or DisputantFrequency <> AgeTotal Or GenderTotal <> EthnicityTotal Or AgeTotal <> LanguageTotal Or AgeTotal <> IncomeTotal Or AgeTotal <> HomelessTotal Or AgeTotal = 0 Then
Range("I39").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Else
Range("I39").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
End If
If DisputantTotal <> EthnicityTotal Or DisputantFrequency <> EthnicityTotal Or EthnicityTotal <> AgeTotal Or EthnicityTotal <> LanguageTotal Or EthnicityTotal <> IncomeTotal Or EthnicityTotal <> HomelessTotal Or EthnicityTotal = 0 Then
Range("I50").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Else
Range("I50").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
End If
If DisputantTotal <> LanguageTotal Or DisputantFrequency <> LanguageTotal Or LanguageTotal <> AgeTotal Or LanguageTotal <> EthnicityTotal Or LanguageTotal <> IncomeTotal Or LanguageTotal <> HomelessTotal Or LanguageTotal = 0 Then
Range("I65").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Else
Range("I65").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
End If
If DisputantTotal <> IncomeTotal Or DisputantFrequency <> IncomeTotal Or IncomeTotal <> AgeTotal Or IncomeTotal <> EthnicityTotal Or IncomeTotal <> HomelessTotal Or IncomeTotal = 0 Then
Range("I73").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Else
Range("I73").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
End If
If DisputantTotal <> HomelessTotal Or DisputantFrequency <> HomelessTotal Or HomelessTotal <> AgeTotal Or HomelessTotal <> EthnicityTotal Or IncomeTotal <> HomelessTotal Or HomelessTotal = 0 Then
Range("I85").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Else
Range("I85").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingHyperlinks:=True, AllowSorting:= _
True, AllowFiltering:=True, AllowUsingPivotTables:=True
Range("I85").Select
End Sub
BTW用户按下按钮使宏运行。
由于