Select Range as far as.....

  • Thread starter Thread starter universal
  • Start date Start date
U

universal

Hello All,

Id like to be able to highlight a row (whichever I have the curso
currently on) but only as far as column AP.

As a start Ive got:

Sub VirtualRuler()

ActiveCell.EntireRow.Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
End Sub

But this highlights all the way across the page.

As a further point, it would be quite nice if the same button tha
turns it on then removes it again, but I suspect the best way to d
this would be to re-colour the whole page
 
universal??,

Try this:

Sub VirtualRuler()
Range(Range("A" & ActiveCell.Row), _
Range("AP" & ActiveCell.Row)).Select
With Selection.Interior
..ColorIndex = 36
..Pattern = xlSolid
End With
End Sub

John
 
Sub VirtualRuler()
Cells.Interior.ColorIndex = xlNone
With Cells(ActiveCell.Row,1).Resize(1,42).Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
End Sub
 
universal said:
Hello All,

Id like to be able to highlight a row (whichever I have the cursor
currently on) but only as far as column AP.

As a start Ive got:

Sub VirtualRuler()

ActiveCell.EntireRow.Select
With Selection.Interior
ColorIndex = 36
Pattern = xlSolid
End With
End Sub

But this highlights all the way across the page.

As a further point, it would be quite nice if the same button that
turns it on then removes it again, but I suspect the best way to do
this would be to re-colour the whole page.

If I understand correctly, you want something like this:
Sub Coloring()
Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 42)).Select
With Selection.Interior
If .ColorIndex <> -4142 Then .ColorIndex = -4142 Else _
.ColorIndex = 36
Pattern = xlSolid
End With
End Sub

' You don't even need to select the cells.
Sub Coloring2()
With Range(Cells(ActiveCell.Row, 1), _
Cells(ActiveCell.Row, 42)).Interior
If .ColorIndex <> -4142 Then .ColorIndex = -4142 Else _
.ColorIndex = 36
Pattern = xlSolid
End With
End Sub

Regards,
 
Back
Top