| 
    
     |  | 所定のシートに下記のコードがあります。 E列の選択の際に、同一列に選択セルと同じ値がある場合に当該セルおよび当該セルと同じ行のB列について、セルの色が変わるという仕様です。
 この仕様で実行時エラー1004が発生します。
 このシートの保護(A1:A4とA2:H201以外を保護)と"Selection.SpecialCells" を併用していることが原因ではないかと考えています。
 シートの保護は現状の範囲としたいのですが、エラーの回避策はどのようにすればよろしいのでしょうか。ご教示のほど何卒よろしくお願い申し上げます。
 
 Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 If Target.Column <> 5 Then Exit Sub
 Dim Trang As Range, Lrang As Range
 Application.EnableEvents = False
 Selection.SpecialCells(xlCellTypeConstants, 23).Interior.ColorIndex = 0
 For Each Lrang In Selection.SpecialCells(xlCellTypeConstants, 23)
 If Lrang.Address <> ActiveCell.Address Then
 If Lrang.Value = ActiveCell.Value Then
 Lrang.Interior.ColorIndex = 38
 Lrang.Offset(0, -3).Interior.ColorIndex = 40
 ActiveCell.Interior.ColorIndex = 38
 ActiveCell.Offset(0, -3).Interior.ColorIndex = 40
 End If
 End If
 Next
 Application.EnableEvents = True
 End Sub
 
 |  |