I have created a serial number list and when a cell is selected within a specified range the macro "X"s the cell and vice versa. But when I click on a cell outside the range specified it throws an Run Time Error 91: Object Variable or With Block Variable not set. Any Insight would be greatly appreciated.
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim rngToCheck As Range
Set rngToCheck = Range("A5:T54")
Dim z As String
z = "T55"
If Intersect(Target, rngToCheck) Then
If Target.Borders(xlDiagonalDown).Color = False Then
Target.Borders(xlDiagonalDown).LineStyle = XlLineStyle.xlContinuous
Target.Borders(xlDiagonalUp).LineStyle = XlLineStyle.xlContinuous
Target.Borders(xlDiagonalDown).Color = vbRed
Target.Borders(xlDiagonalUp).Color = vbRed
Range(z).Value = Range(z).Value + 1
Else:
Target.Borders(xlDiagonalDown).LineStyle = XlLineStyle.xlLineStyleNone
Target.Borders(xlDiagonalUp).LineStyle = XlLineStyle.xlLineStyleNone
Range(z).Value = Range(z).Value - 1
End If
End If
End Sub
Bookmarks