I have the following code:
Case "END-BOX"
EndBox = ActiveCell.Row
Selection.Offset(-1, 2).Select
Selection.ClearContents
Rows(2).Insert Shift:=xlDown
TotalCols = ActiveSheet.UsedRange.Columns.Count
Col = 4
Cells(EndBox, Col).Select
For i = EndBox To 1 Step -1
If Cells(i, Col).Value <> "" Then
n = n + 1
Else
Cells(i, Col).Value = n
Cells(i, Col).Interior.ColorIndex = 4
n = 0
End If
Next
Range(EndBox).Select
Selection.Offset(1, -2).Select
It results in green cells appearing on the end-box lines, as well as the new-box lines. I would only like the new-box lines to color. Is there any way to modify the code so that it does do this?
Here is my workbook.
Get rid of the line that says:
Cells(i, Col).Interior.ColorIndex = 4This is the line that is setting the color of the cells.
To color ONLY the rows with “new-box” in column B, change that line to:
If Cells(i, Col).Offset(0, -2).Value = "new-box" Then Cells(i, Col).Interior.ColorIndex = 4Note: this will not undo color formatting previously applied.