2016-06-20 3 views
0

양식에 대한 작업을하고 있습니다.이 시트의 모든 합계는 서로 같다고 가정합니다. If 문을 사용하여 합계가 모두 같은지 확인하지만 변수를 연결하기 위해 Or를 사용하는 경우 IF 문에서 합계의 한 실수로 인해 모든 필드가 빨간색이되어 사용자가 실수를 빨리 찾을 수 없습니다. 변수를 연결하기 위해 And를 사용하면 버그가 발생합니다. 왜냐하면 2 개의 개별 합계에 오류가 있으면 오류가 전혀 표시되지 않기 때문입니다. 버튼을 누르면 프로그램이 모든 합계를 비교하여 다른 사람들과 일치하지 않는 항목 만 빨간색으로 만들도록하고 싶습니다. 어쨌든 저에게 그렇게 할 수 있습니까? 논리적 인 질문이 많지만 내 코드는 다음과 같습니다.VBA 빨간색으로 일치하지 않는 셀을 바꾸고 싶습니다.

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 

사용자가 매크로를 실행하기 위해 버튼을 누릅니다.

감사합니다.

+0

무엇이 다른 합계를 정의합니까? 반이 하나이고 다른 반이 다른 경우 어떻게됩니까? 어떤 것이 강조 될 것인가? 모두, 더 낮은 것 또는 더 높은 것? –

+0

@ScottCraner 사용자가 비즈니스에 따라 원하는 번호를 입력 할 수있는 문제가 있지만 적은 수의 데이터가 누락되었음을 나타 내기 때문에 낮은 숫자를 강조 표시하는 것이 바람직 할 수 있습니다. 그 합계가 다른 것보다 적 으면 양식. – Artak

답변

0

이렇게하려면 조건부 서식을 사용할 수 있습니다. 이 공식을 사용

=SUMPRODUCT(($I$19=I19)+($I$24=I19)+($I$31=I19)+($I$39=I19)+($I$50=I19)+($I$65=I19)+($I$73=I19)+($I$79=I19)+($I$85=I19))<5 

는 만 합계에 적용 확인합니다 :

=$I$19,$I$24,$I$31,$I$39,$I$50,$I$65,$I$73,$I$79,$I$85 

enter image description here

그것은 대부분의 다른 부분에 강조 표시됩니다. 모두 다르면 모두 강조 표시됩니다.

+0

고마워요! 나는 네가 필요로하는 것을 수용하기 위해 네가 보낸 것을 내가 엉망으로 만들었지 만 네가 말했던 것처럼 정확히 일하게 만들 수는 없었다. 오류가있을 때 셀은 빨간색으로 변하지만 대다수와 다른 셀만 강조 표시합니다. 대신 모든 셀을 강조 표시합니다. 당신이 보낸 수식을 바꾸기 전에 저도 마찬가지였습니다. 어떤 충고? – Artak

+0

모두 다르다면 모두 강조 표시하고 싶지는 않습니까? 합의가 없으면 대다수, 무시할 것을 어떻게 알 수 있습니까? –

+0

그들이 모두 다르다면 모든 것을 강조하고 싶지만 문제는 하나를 제외하고 모두 똑같이 만들었지 만 모든 세포가 틀린 것 대신에 빨간색으로 변하게 만든다. 사용자가 어떤 총합이 잘못되었는지 빠르게 볼 수 있기를 원하므로 사진에있는 것처럼 잘못된 총합 만 강조하면됩니다. 이것은 하나의 총합이 잘못되었을 때 발생합니다 : http://i.stack.imgur.com/743f8.png – Artak

관련 문제