プロが教えるわが家の防犯対策術!

下記のコードは某氏が頂戴いたしました。
一部付け加えました。
エラーはでませんが、強いていうなら
エラー回避対策教えていただけたら、良いのですが。

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Target, Range("E:E,G:G")) Is Nothing Then
If .Row Mod 2 = 1 Then
If IsDate(.Value) Then
Cells(.Row, 5).Interior.ColorIndex = 6
Cells(.Row - 1, 5).Interior.ColorIndex = 6
Else
Cells(.Row, 5).Interior.ColorIndex = xlNone
Cells(.Row - 1, 5).Interior.ColorIndex = xlNone
End If
Else
Cells(.Row, 5).Interior.ColorIndex = xlNone
Cells(.Row - 1, 5).Interior.ColorIndex = xlNone
End If


ElseIf Not Intersect(Target, Range("B:B")) Is Nothing Then
If IsDate(Cells(.Row, 2).Text) Then
If Cells(.Row, 2).Value Then
Cells(.Row, 1).Interior.ColorIndex = 3
Else
Cells(.Row, 1).Interior.ColorIndex = xlColorIndexNone
End If
Else
Cells(.Row, 1).Interior.ColorIndex = xlColorIndexNone
End If


ElseIf Not Intersect(Target, Range("K:L")) Is Nothing Then
If IsDate(Cells(.Row, 11).Text) And IsDate(Cells(.Row, 12).Text) Then
If Cells(.Row, 11).Value >= Cells(.Row, 12).Value Then
Cells(.Row, 12).Interior.ColorIndex = 3
Else
Cells(.Row, 12).Interior.ColorIndex = xlColorIndexNone
End If
Else
Cells(.Row, 12).Interior.ColorIndex = xlColorIndexNone
End If
End If

End With
End Sub

A 回答 (1件)

こんにちは



>エラーはでませんが、強いていうなら
>エラー回避対策教えていただけたら、良いのですが。
『発生しないエラーの回避対策』って意味がわかりかねます。
いったい、何をなさりたいのでしょうか??

もっとも、ざっと見ただけですが、E1セル又はG1セルを変更するとエラーになりそうな…
多分、1行目はタイトル行なので、普通に使用する限りは変更などしないのでしょうけれど。
セルをロックしておけば変更できなくなるので、それがエラー回避策になっているとも言えるでしょう。
    • good
    • 0
この回答へのお礼

失礼いたしました。

お礼日時:2019/09/17 10:46

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!