Results 1 to 5 of 5

Thread: Highlighting column and row.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86

    Lightbulb Highlighting column and row.

    Hi, let's assume everytime Im clicking a cell in Excel, It should intersect the column and row...It can be highlighted with any color or simply default...how to do it..?thanks for the help.

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    VB Code:
    1. [color="#0000A0"]Private[/color] [color="#0000A0"]Sub[/color] Worksheet_SelectionChange([color="#0000A0"]ByVal[/color] Target [color="#0000A0"]As[/color] Range)
    2.     Cells.Interior.ColorIndex = 0
    3.  
    4.     Columns(Target.Column).Interior.ColorIndex = 36
    5.     Rows(Target.Row).Interior.ColorIndex = 36
    6. [color="#0000A0"]End[/color] [color="#0000A0"]Sub[/color]

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86
    I've commented out the first line coz i do not want my original color to be erased...but for this:
    PHP Code:
     Columns(Target.Column).Interior.ColorIndex 36
        Rows
    (Target.Row).Interior.ColorIndex 36 
    whenever i remove my cursor to other cell, the yellow lines seems to be jus there. they do not disappear away.how can u change it? What I actually wanted was only the y and -x axis but urs has also -y and x axis..can it be removed?? Thanks for helping.

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    First off, the Cells.Interior.ColorIndex = 0" line clears all of the cells colours which have been set, i.e. for every cell in the active worksheet, the interior colour is set back to the default white background.

    Next up, try this code:
    [Highlight=VB]
    VB Code:
    1. [color="#0000A0"]Private[/color] [color="#0000A0"]Sub[/color] Worksheet_SelectionChange([color="#0000A0"]ByVal[/color] Target [color="#0000A0"]As[/color] Range)
    2.     [color="#0000A0"]Dim[/color] rngActiveCell [color="#0000A0"]As[/color] Range
    3.     [color="#0000A0"]Set[/color] rngActiveCell = Range(CStr(Mid(ActiveCell.Address, 2, CInt(InStr(Right(ActiveCell.Address, _
    4.     CInt(Len(ActiveCell.Address) - 1)), "$") - 1))) & ActiveCell.Row)
    5.    
    6.     Cells.Interior.ColorIndex = 0
    7.    
    8.     Range(CStr(Mid(Target.Address, 2, CInt(InStr(Right(Target.Address, CInt(Len(Target.Address) - 1)), _
    9.     "$") - 1))) & "1:" & CStr(Mid(Target.Address, 2, CInt(InStr(Right(Target.Address, _
    10.     CInt(Len(Target.Address) - 1)), "$") - 1))) & Target.Row).Interior.ColorIndex = 36
    11.    
    12.     Range("A" & Target.Row & ":" & CStr(Mid(Target.Address, 2, CInt(InStr(Right(Target.Address, _
    13.     CInt(Len(Target.Address) - 1)), "$") - 1))) & Target.Row).Interior.ColorIndex = 36
    14.    
    15.     rngActiveCell.Select
    16. [color="#0000A0"]End[/color] [color="#0000A0"]Sub[/color]
    Last edited by alex_read; Apr 8th, 2003 at 08:15 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86
    Thanks for ur codes....Im having problems when I need to use it over a pivot table which is "protected". It needs to be.. coz I do not want users to make changes to it..Anyway,thanks for ur help n if I have any prob on the way, I'll get back to u buddy..
    Cheers
    ITboy

Posting Permissions

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



Click Here to Expand Forum to Full Width