View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Beto[_3_] Beto[_3_] is offline
external usenet poster
 
Posts: 140
Default Select Range as far as.....

universal < wrote:
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,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.