Consulting

Results 1 to 2 of 2

Thread: Help with highlight macro

  1. #1
    VBAX Newbie
    Joined
    Jun 2007
    Posts
    1
    Location

    Help with highlight macro

    Hi

    The following macro is on the forums to change the color of a row and column of the cell that you selected:

    Option Explicit

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim RngRow As Range
    Dim RngCol As Range
    Dim RngFinal As Range
    Dim Row As Long
    Dim Col As Long

    Cells.Interior.ColorIndex = xlNone

    Row = Target.Row
    Col = Target.Column

    Set RngRow = Range("A" & Row, Target)
    Set RngCol = Range(Cells(1, Col), Target)
    Set RngFinal = Union(RngRow, RngCol)

    RngFinal.Interior.ColorIndex = 6

    End Sub


    It does exactly what I want, but it changes the existing color on my spreadsheet to white. Is there any way to keep the existing color on my spreadsheet while highlighting the row of the cell selected?

    Thanx

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    here is an alternative that leaves the colours but will wipe out any conditional formatting

    [vba]


    '----------------------------------------------------------------
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    '----------------------------------------------------------------
    Cells.FormatConditions.Delete
    With Target
    With .EntireRow
    .FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
    With .FormatConditions(1)
    With .Borders(xlTop)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = 5
    End With
    With .Borders(xlBottom)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = 5
    End With
    .Interior.ColorIndex = 20
    End With
    End With
    With .EntireColumn
    .FormatConditions.Delete
    .FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
    With .FormatConditions(1)
    With .Borders(xlLeft)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = 5
    End With
    With .Borders(xlRight)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = 5
    End With
    .Interior.ColorIndex = 20
    End With
    End With

    .FormatConditions.Delete
    .FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
    .FormatConditions(1).Interior.ColorIndex = 36
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •