Consulting

Results 1 to 15 of 15

Thread: Solved: Highlight the entire row on click

  1. #1
    VBAX Contributor
    Joined
    May 2008
    Posts
    109
    Location

    Solved: Highlight the entire row on click

    I am wondering if exists the chance to highlight the entire row where I click on selected cell. For instance, I select a cell in row 5, I want the entire row to be highlighted. If I then select a cell in Row 8, I want Row 5 to return to normal, and Row 8 to be highlighted.

    Thanks for any help

    sasa

  2. #2
    VBAX Regular
    Joined
    Jan 2006
    Posts
    28
    Location

    Smile

    Good morning sasa
    Quote Originally Posted by sasa
    to highlight the entire row where I click on selected cell.
    Something like this will work OK, when placed into the code module of the sheet in question. This will also restore the column you clicked on as the active cell.

    Here's the caveat : a routine like this works on the selection change event, which means that the routine is run every time the selection is changed. In time every time the routine is run your undo stack is cleared, therefor using a routine such as this means that you will lose your undo ability. There is no way around this.

    [vba]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim a As String
    a = ActiveCell.Address
    ActiveCell.EntireRow.Select
    Range(a).Activate
    End Sub[/vba]

    If the caveat bit doesn't put you off, you might like to have a look at Chip Pearson's Rowliner add-in - it's a more sophisticated way of achieving the result :
    http://www.cpearson.com/excel/RowLiner.htm

    HTH

    DominicB

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    One way

    [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]

    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.
    ____________________________________________
    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

  4. #4
    Quote Originally Posted by xld
    One way
    Bob, this one is very pretty

    One thing to add, though. It didn't worked for me until I realized that in this part of the code
    [vba].FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"[/vba] the expression "TRUE" must be replaced with the local word that corresponds to TRUE. In Hungarian Excel, it looks like this:
    [vba].FormatConditions.Add Type:=xlExpression, Formula1:="IGAZ"[/vba] I'm not sure what language is used in Alderney, but for others, this may be of help.

    Jimmy
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  5. #5
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    228
    Location
    Hi xld,

    I just pated this code into a worksheet and it works really well.

    This is something that I could use for another project I am managing, it would help users to identify the relevand data set.

    What would I need to do to the code to embed it into a spreadsheet that I send out to others. Would this then be blocked when they open the sheet??

    Thanks,

    Marshybid

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by JimmyTheHand
    Bob, this one is very pretty

    One thing to add, though. It didn't worked for me until I realized that in this part of the code
    [vba].FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"[/vba] the expression "TRUE" must be replaced with the local word that corresponds to TRUE. In Hungarian Excel, it looks like this:
    [vba].FormatConditions.Add Type:=xlExpression, Formula1:="IGAZ"[/vba] I'm not sure what language is used in Alderney, but for others, this may be of help.

    Jimmy
    Wasn't aware of this Jimmy. When you add a formula to a cell in VBA, you always use English for the functions, but I guess not for the booleans.

    Can you try this for me

    [vba]

    ActiveCell.FormulaR1C1 = "=IF(A1=17,TRUE,FALSE)"
    [/vba]

    I know it is a rfubbish formula, but how does it map in your Excel?
    ____________________________________________
    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

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by marshybid
    Hi xld,

    I just pated this code into a worksheet and it works really well.

    This is something that I could use for another project I am managing, it would help users to identify the relevand data set.

    What would I need to do to the code to embed it into a spreadsheet that I send out to others. Would this then be blocked when they open the sheet??

    Thanks,

    Marshybid
    If you just paste it into that workbook, it will just need macros enabling.

    Be aware of its one (BIG!!) limitation, it wipes out any conditional formatting on that sheet.

    I have a version that is an addin that sets it by sheet, by workbook, and can toggle it on and off.
    ____________________________________________
    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

  8. #8
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    228
    Location
    Thanks for that xld. Is it possible to see the version that you have as an addin??

    Marshybid

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sure. It might take me a cuple of days to dig out as it is on another machine. I never published it.
    ____________________________________________
    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

  10. #10
    Quote Originally Posted by xld
    [vba]ActiveCell.FormulaR1C1 = "=IF(A1=17,TRUE,FALSE)"[/vba]
    I know it is a rfubbish formula, but how does it map in your Excel?
    Running the above line I got this formula in the active cell:
    =HA('A1'=17;IGAZ;HAMIS)
    The result was #NAME? error, until I removed the apostrophes around A1.
    Don't know how they got there Nevertheless, the booleans got translated.

    I checked the active cell's conditional format (set by your code with the original "TRUE") and the expression was
    ="TRUE"
    So, it didn't get translated here. Strangely, if I write "TRUE" (string) into the cell, it still does nothing.

    I don't understand. But won't miss a sleep ovet it

    Jimmy

    EDIT:
    I got the formula right. It should have been
    [vba]ActiveCell.Formula = "=IF(A1=17,TRUE,FALSE)"[/vba]
    (without "R1C1")
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  11. #11
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    228
    Location
    Thanks xld, I'll look forward to seeing it in a few days.

    Marshybid

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by JimmyTheHand
    Running the above line I got this formula in the active cell:
    =HA('A1'=17;IGAZ;HAMIS)
    The result was #NAME? error, until I removed the apostrophes around A1.
    Don't know how they got there Nevertheless, the booleans got translated.
    As you correctly surmised, it was because I used the FormulaR1C1, but added an A1 formula. I guess Excel puts quotes around the A1 because it is being supplid in R1C1 type formula it thinks the A1 is a name, and you can't have a name that is a cell reference.
    ____________________________________________
    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

  13. #13
    VBAX Contributor
    Joined
    May 2008
    Posts
    109
    Location
    Hi xld,
    You are so great ! The best in the world.
    I confirm the necessity to change the expression "TRUE".
    I tried and it works very well. But how I can deactivate the macro ?
    sasa

  14. #14
    VBAX Contributor
    Joined
    May 2008
    Posts
    109
    Location
    Hi DominicB,
    I tried your routine, it works too, and does not wipe out any conditional formatting on that sheet.This is good for me because I have a lot of conditional formatted columns. Is there a way to off your code and on again when I need it ?

    Thanks a lot

    sasa

  15. #15
    VBAX Contributor
    Joined
    May 2008
    Posts
    109
    Location
    Hi All,
    what about this code ?
    It was good for me.
    Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Static rr
    Static cc

    If cc <> "" Then
    With Columns(cc).Interior
    .ColorIndex = xlNone
    End With
    With Rows(rr).Interior
    .ColorIndex = xlNone
    End With
    End If

    r = Selection.Row
    c = Selection.Column
    rr = r
    cc = c

    With Columns(c).Interior
    .ColorIndex = 20
    .Pattern = xlSolid
    End With
    With Rows(r).Interior
    .ColorIndex = 20
    .Pattern = xlSolid
    End With

    It looks like it does not wipe the conditional formatting and it
    allows me the cut and copy option.

    Thanks again !!!!

    sasa
    End Sub

Posting Permissions

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