2012-01-08 11 views
1

私はVBAに慣れていませんが、3つ以上の条件付き書式を許可するように私のExcelを変更する必要がありました。VBAエラー13種類:不一致

私は以下のコードをオンラインで見つけ、コンテンツに応じてセルの色を6種類の値から選択して変更したいと考えています。

私のコードは次のとおりです。

Private Sub Worksheet_Change(ByVal Target As Range) 
    Set MyPlage = Range("G3:AG115") 

    For Each Cell In MyPlage 
    If Cell.Value = "." Then 
     Cell.Interior.ColorIndex=28 
     Cell.Font.Bold = True 
    End If 

    If Cell.Value = "X1" Then 
     Cell.Interior.ColorIndex=32 
     Cell.Font.Bold = True 
    End If 

    If Cell.Value = "1X" Then 
     Cell.Interior.ColorIndex=6 
     Cell.Font.Bold = True 
    End If 

    If Cell.Value = "2X" Then 
     Cell.Interior.ColorIndex=45 
     Cell.Font.Bold = True 
    End If 

    If Cell.Value = "3X" Then 
     Cell.Interior.ColorIndex=4 
     Cell.Font.Bold = True 
    End If 

    If Cell.Value = "XY" Then 
     Cell.Interior.ColorIndex=44 
     Cell.Font.Bold = True 
    End If 

    If Cell.Value = "bt" Then 
     Cell.Font.ColorIndex=27 
     Cell.Interior.ColorIndex=27 
    End If 

    If Cell.Value = "bl" Then 
     Cell.Font.ColorIndex=28 
     Cell.Interior.ColorIndex=28 
    End If 

    If Cell.Value <> "bt" And Cell.Value <> "bl" And Cell Value <> "." And Cell.Value <> "X1" And Cell.Value <> "1X" And Cell.Value <> "2X" And Cell.Value <> "3X" And Cell.Value <> "XY" Then 
     Cell.Interior.ColorIndex=xlNone 
    End If 
    Next 
End Sub 

内容は、BTとBLは、これらの行が強調表示されていることを確認するには書かれている他のドロップダウンリストから、どちらかを選択します。

コンテンツを変更しようとすると、Error: 13 Type Mismatchと表示されます。

ライン

If Cell.Value = "." Then 

は(私は問題が"."であるかもしれないと思ったが、私は説明書のセットを削除した場合、その後の行

If Cell.Value = "X1" Then 

が強調表示される)誤差源として強調されています

私はグーグルで、あなたがエラーThen Nextの場合、どのように私はこれを正確にコード化し、私は悪いクイックフィックスよりもコーディングの問題を解決します。

誰かが私がどこに間違っているのかについてのアイデアがあれば/素晴らしい解決策があります。あなたは(例えば#NA#DIV/0など)シート内の任意のエラー値を持っている場合は

+1

このエラーの原因は何ですか?私は暗黙的と明示的な変数宣言の両方で様々な種類のコンテンツを試しましたが、このエラーを再現することはできません。 – GSerg

+0

3つの条件付きフォーマットに制限されているxl03を使用していると推測します(対応策はありますが)。 – brettdj

+1

これはあなたの質問に対する答えではありませんが、なぜFor Each Cell In MyPlage'をチェックしている間に 'For Each Cell In Target'をチェックできるのでしょうか? –

答えて

2

EDIT

そしてIf Cell...行は失敗します

変更し、それに細胞内でどのような

Private Sub Worksheet_Change(ByVal Target As Range) 
    Dim Cell as Range 
    Set MyPlage = Range("G3:AG115") 
    For Each Cell In MyPlage.Cells 
     If Not IsError(Cell) Then 
      If Cell.Value = "." Then 
       Cell.Interior.ColorIndex=28 
       Cell.Font.Bold = True 
      End If 

      etc 

     End If 
    Next 
+0

これで問題が解決しました。ありがとうございました。 –

+0

@ジェニーあなたが満足していると答えたら、トゥーはそれを受け入れるべきです(ダニをクリックしてください)[Meta](http://meta.stackexchange.com/q/5234/159408)を参照してください。 –

関連する問題