Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Highlight Current Row in Excel (VBA)

  1. #11
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by hvg88 View Post
    Thanks to all experts,
    I want to know what for all worksheet to highlight current raw?
    Put this code in the workbook's code module (do not put it in any of the worksheet modules)...
    Code:
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
      Cells.Interior.ColorIndex = xlColorIndexNone
      Target.EntireRow.Interior.ColorIndex = 6
    End Sub
    If you are not sure where the workbook module is, look over at the Project Explorer window within the VBA editor (CTRL+R if you do not see it) and then double-click the entry labeled ThisWorkbook... that will open the workbook code module... copy paste the code in it. Remember though, with this code you cannot have any other manually colored cells as the code will remove their colors when executing.

  2. #12
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    code w/o erasing original highlighted color

    is there a code that does the same thing (highlight active row) with out removing original highlighted color after cell is no longer active?



    Quote Originally Posted by Rick Rothstein View Post
    Put this code in the workbook's code module (do not put it in any of the worksheet modules)...
    Code:
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
      Cells.Interior.ColorIndex = xlColorIndexNone
      Target.EntireRow.Interior.ColorIndex = 6
    End Sub
    If you are not sure where the workbook module is, look over at the Project Explorer window within the VBA editor (CTRL+R if you do not see it) and then double-click the entry labeled ThisWorkbook... that will open the workbook code module... copy paste the code in it. Remember though, with this code you cannot have any other manually colored cells as the code will remove their colors when executing.

  3. #13
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0
    i found this code, it doesnt change the original highlighted color

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    ActiveSheet.Rows(Target.Row).Select ' highlite entire row
    Target.Activate ' select the cell

    End Sub

  4. #14
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by luna View Post
    i found this code, it doesnt change the original highlighted color

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    ActiveSheet.Rows(Target.Row).Select ' highlite entire row
    Target.Activate ' select the cell

    End Sub
    You can simplify that first line of code like this...

    Target.EntireRow.Select

  5. #15
    Member Transformer's Avatar
    Join Date
    Mar 2012
    Posts
    91
    Rep Power
    13
    Quote Originally Posted by luna View Post
    i found this code, it doesnt change the original highlighted color

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    ActiveSheet.Rows(Target.Row).Select ' highlite entire row
    Target.Activate ' select the cell

    End Sub
    And following can be used to highlight row and column both

    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        Application.EnableEvents = False
        Range(Target.EntireRow.Address & "," & Target.EntireColumn.Address).Select 'OR Union(Target.EntireRow, Target.EntireColumn).Select
        Target.Activate
        Application.EnableEvents = True
        
    End Sub
    Last edited by Transformer; 04-29-2013 at 05:08 PM.
    Regards,

    Transformer

  6. #16
    Junior Member
    Join Date
    Jul 2013
    Posts
    1
    Rep Power
    0
    Although this is excellent, is there a code that will do the same, but, if selecting multiple cells (2 or more) with my mouse, the code becomes void?

    Quote Originally Posted by luna View Post
    i found this code, it doesnt change the original highlighted color

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    ActiveSheet.Rows(Target.Row).Select ' highlite entire row
    Target.Activate ' select the cell

    End Sub

  7. #17
    Member Transformer's Avatar
    Join Date
    Mar 2012
    Posts
    91
    Rep Power
    13
    You can check cells count.
    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        If Target.Cells.Count >= 2 Then Exit Sub
        Application.EnableEvents = False
        Range(Target.EntireRow.Address & "," & Target.EntireColumn.Address).Select 'OR Union(Target.EntireRow, Target.EntireColumn).Select
        Target.Activate
        Application.EnableEvents = True
        
    End Sub
    Quote Originally Posted by dypang87 View Post
    Although this is excellent, is there a code that will do the same, but, if selecting multiple cells (2 or more) with my mouse, the code becomes void?
    Last edited by Transformer; 07-31-2013 at 06:48 AM.
    Regards,

    Transformer

Similar Threads

  1. Replies: 4
    Last Post: 06-01-2013, 01:08 PM
  2. Highlight Active Cell’s Row and Column
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 05-17-2013, 12:32 AM
  3. Replies: 6
    Last Post: 05-16-2013, 09:56 AM
  4. Help- Locking column basis current date.
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 1
    Last Post: 03-25-2013, 04:44 PM
  5. Moving Current Latest Data To New Workbook
    By Terry in forum Excel Help
    Replies: 1
    Last Post: 01-19-2013, 12:37 AM

Tags for this Thread

Posting Permissions

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