Revise formula (Stop color line)

ironsides

Well-known Member
Joined
Aug 12, 2002
Messages
575
Sub ColorLine()
Dim LR As Long, i As Long
LR = Range("g" & Rows.Count).End(xlUp).Row
For i = 7 To LR
With Range("g" & i)
If .Value = "" Then .Offset(, -6).Resize(, 28).Interior.ColorIndex = 4
End With
Next i
End Sub

Formula works well
except I want the color to stop on col AC
instead of continuing across entire sheet
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Code:
Sub ColorLine()
    Dim LR As Long, i As Long
    LR = Range("g" & Rows.Count).End(xlUp).Row
    For i = 7 To LR
        If Cells(7, i) = "" Then Range(Cells(i, 1), Cells(i, 29)).ColorIndex = 4
    Next i
End Sub

Edited because I misread the with statement.
 
Last edited:
Upvote 0
Thanks but the color line
still continues past the col specified
continuing across the entire sheet


ironsides
 
Upvote 0
Thanks but the color line
still continues past the col specified
continuing across the entire sheet


ironsides


That's impossible. Is there other code that is going into this macro? The range that I specify:

Code:
[COLOR=#333333]Range(Cells(i, 1), Cells(i, 29)).ColorIndex = 4[/COLOR]

Is from column 1 (A) to column 29 (AC). It doesn't affect any other cells outside of that.


Code:
Sub ColorLine()
    Dim LR As Long, i As Long
    LR = Range("g" & Rows.Count).End(xlUp).Row
    For i = 7 To LR
        If Cells(i, 7) = "" Then Range(Cells(i, 1), Cells(i, 29)).ColorIndex = 4
    Next i
End Sub


I did notice a small error so I just fixed that....
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,669
Members
448,977
Latest member
moonlight6

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top