セルの色に基づいてセルに数値を挿入するスクリプトを実行しようとしています。色が赤の場合は、# 1 を挿入します。スプレッド シートには 380 行ありますが、スクリプトは行 346 で実行を停止します (1 を挿入します)。以下のスクリプト:
Sub InsertOne()
Dim endRow As Long
Dim colorD As Range
Dim Cell As Range
endRow = Sheets(1).Cells(Sheets(1).Rows.Count, "C").End(xlUp).Row
'Ensure ending row is at least Row 2
If endRow < 2 Then
endRow = 2
End If
Set colorD = Range("F2", Range("F" & Rows.Count).End(xlUp))
'Loop through each cell in Column D
For Each Cell In colorD
If Cell.Interior.ColorIndex = 3 Then
Cell.Value = 1
End If
Next Cell
End Sub