+ Reply to Thread
Results 1 to 3 of 3

how to automatically highlight the whole row?

Hybrid View

  1. #1
    Registered User
    Join Date
    01-14-2012
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    Excel 2007
    Posts
    1

    how to automatically highlight the whole row?

    Is there any option to highlight the whole row when a cell is selected? That means when i move from one cell to another, I expect the whole row that contains the second cell to be highlighted. It would be very helpful for me to work on sheets with larger number of columns.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: how to automatically highlight the whole row?

    Right click on your sheet and select View-> Code. Enter this code in there -
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Rows(Target.Row & ":" & Target.Row).Select
    End Sub
    Now save your file and come back to the sheet. Whichever cell you click on, the row will be highlighted.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: how to automatically highlight the whole row?

    That code will highlight the whole row because it is selected. Not a good option if you actually want to work with the cell tht was originally selected

    Option Explicit
    Const iNoColour As Integer = Not (0)
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim iColour As Integer
        ' Note: Don't use IF you have Conditional formating that you want to keep!
        On Error Resume Next
        iColour = Target.Interior.ColorIndex
        ' Leave On Error ON for Row offset errors
        If iColour < 0 Then
            iColour = 34
        Else: iColour = iColour + 1
        End If
        ' Need this test in case Font colour is the same
        If iColour = Target.Font.ColorIndex Then iColour = iColour + 1
        Cells.FormatConditions.Delete
        ' Horizontal colour highlight
        With Target
            .EntireRow.FormatConditions.Add Type:=2, Formula1:=iNoColour    'Or just 1 '"TRUE"
            .EntireRow.FormatConditions(1).Interior.ColorIndex = iColour
        End With
    End Sub
    Worksheet event code is stored on a worksheet module. To add it to your worksheet, do the following:

    Copy the code
    Select the worksheet in which you the code to run
    Right click on the sheet tab and choose View Code, to open the Visual Basic Editor.
    Where the cursor is flashing, choose Edit | Paste
    Last edited by royUK; 01-14-2012 at 02:49 PM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1