2016-06-20 1 views
0

私は代理店に発送するためのフォームを作成しています。この特定のシートについては、合計がすべて同じであると考えられます。 Ifステートメントを使用して合計が等しいかどうかを確認しましたが、Orを使用して変数を接続すると、IFステートメントで、合計の1つのミスがすべてのフィールドを赤にするので、ユーザーは間違いをすばやく見つけることができません。また、2つの別々の合計にエラーがあると、エラーが全く表示されないため、変数を接続するためにAndを使用するとバグが発生します。ボタンを押すと、プログラムはすべての合計を比較し、他のボタンと一致しないものだけを赤にしたいと思います。その論理的な質問の多くは、ここに私のコードです: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

異なる合計を定義するものは何ですか?半分が1であり、残りの半分が別の場合はどうなりますか?どちらが強調表示されますか?すべて、低いか高いか? –

+0

@ScottCraner問題は、ユーザーがビジネスによって必要な任意の番号を入力できるということですが、低い数字を強調表示することは意味がありますそれらの合計が他のものよりも少ない場合のフォーム。 – Artak

答えて

0

これを行うには、条件付き書式設定を使用できます。この式を使用してください:それは大多数の異なるものをハイライト表示されます

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

enter image description here

=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 

は確かにそれが唯一の合計に適用されます。それらがすべて異なる場合、すべてが強調表示されます。

+0

ありがとう!私はあなたが私の必要なものを受け入れるために少し送ったものを使いこなしましたが、あなたが言ったようにそれを正確に働かせることはできませんでした。エラーが発生するとセルは赤くなりますが、大部分とは異なるセルのみがハイライト表示されます。あなたが送った式で何かを変更する前に、それは私にも当てはまりました。何かアドバイス? – Artak

+0

すべてが異なる場合は、それらのすべてをハイライト表示したくないのですか?合意がない場合、過半数、どのように無視するかを知っていますか? –

+0

もしそれらがすべて異なっていれば私はそれをすべて強調したいと思っていますが、問題は1つを除いて全てを等しくしたことですが、それは間違っているものの代わりにすべての細胞を赤に変えます。私はユーザーがすばやく合計が間違っているのを見ることができるようにしたいので、あなたの写真のように間違った合計だけを強調したいと思っています。 これは、1つの合計が間違っているとどうなります:http://i.stack.imgur.com/743f8.png – Artak

関連する問題