次のコードでは、太字の行にアプリケーション定義またはオブジェクト定義のエラーが表示されます。範囲を設定しました。ただし、明らかにExcelはそれを読み取ることができません。なぜそのエラーが表示されるのかわかりません。どんな助けでも大歓迎です!ありがとう。
Public Sub specialattention()
'Loop to check whether issue needs spcial attention
Dim n As Variant
Dim nend As Range
Dim nrng As Range
Dim nnow As Date
Dim ninterval As Integer
ninterval = Sheets("Ranges").Range("AB3").Value
nnow = Sheets("Issues Database").Range("N5").Value
Set nend = Sheets("Issues Database").Range("M1048576").End(xlUp)
Set nrng = Sheets("Issues Database").Range("M6", nend)
For Each n In nrng
If n.Value = "1" And nnow - n.Offset(0, 1).Value >= ninterval Then
n.Offset(0, 2).Value = "1"
Else
n.Offset(0, 2).Value = "0"
End If
'Color Cells that need special attention
If n.Offset(0, 2).Value = "1" Then
Dim xrng1 As Range
Dim xrng2 As Range
Set xrng1 = n.Offset(0, -11)
Set xrng2 = n.Offset(0, -1)
**Sheets("Issues Database").Range(xrng1, xrng2).Interior.ColorIndex = 19**
Else
Dim xrng3 As Range
Dim xrng4 As Range
Set xrng3 = n.Offset(0, -11)
Set xrng4 = n.Offset(0, -1)
**Sheets("Issues Database").Range(xrng2, xrng3).Interior.ColorIndex = 2**
End If
Next
End Sub