+ Reply to Thread
Results 1 to 7 of 7

How to highlight an active row within a selected range in excel

  1. #1
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    How to highlight an active row within a selected range in excel

    Hi guys,

    Please first see the attached sample excel file for your review.

    I used the conditional formatting to highlight an active row with the function below:

    =(CELL("row")=CELL("row",C5))

    The problem with the excel function is it still highlights the row even when I click the cell that is not within the selected range.

    How can I make the row within the selected range to be highlighted only if I select the cells within the range?

    Cheers,
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: How to highlight an active row within a selected range in excel

    Hi jjin
    I'm a bit out of practice so there will be a more elegant implementation and haven't got time at present.
    See the mod to you macro in the attched.
    Should get you going.
    Barry

    jjin Target range 050113 - Excel.xlsm
    If this was helpful then please click the small star icon at the bottom left of my post. A little appreciation goes a long way.

  3. #3
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: How to highlight an active row within a selected range in excel

    Hi barryleajo,

    I have just applied the code to my other workbook then I got the following message:


    Compile Error:
    Ambiguous name detected: Worksheet_SelectionChange

    Below is the copy of the VBA code from my other workbook. Any suggestion?? Thanks.


    ---------------------------------------------------------------------------


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Intersect(Target, Range("$N$21:$Z$98")) Is Nothing Then Exit Sub
    If Target.Count > 1 Then Exit Sub
    If Target <> "" Then
    Range("$AI$21") = Cells(Target.Row, "E").Value
    Range("$AI$23") = Cells(Target.Row, "I").Value
    Range("$AI$35") = Cells(18, Target.Column).Value
    End If

    End Sub


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Intersect(Target, Range("$E$21:$Z$98")) Is Nothing Then Exit Sub
    If Target.Row > 20 And Target.Row < 99 And Target.Column > 4 And Target.Column < 29 Then
    Target.Calculate

    End If

    End Sub

  4. #4
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: How to highlight an active row within a selected range in excel

    Hi jjin
    Looks like your (newly introduced) requirement and the example you posted earlier have got confused.
    Firstly, attachment v2 sorts out your example.
    Secondly, attachment v3 is a mock-up of how I read your requirement and a solution?
    To save us retyping your code etc., if this doesn't meet your requirement then upload a working file.
    Finally, take time to read the forum rules and learn how to enclose your code with code tags.
    You look to be well on with sorting out your problem, well done.
    Barry
    jjin Target range 050113 v2 - Excel.xlsm
    jjin Target range 050113 v3 - Excel.xlsm

  5. #5
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: How to highlight an active row within a selected range in excel

    Hi Barryleajo,

    I can clearly see that my second example has confused you alot. I should have explained it more clearly. Sorry for confusing ya.

    Firstly, the first part of the VBA code I have posted above is the code I copied directly from another workbook (Let's say, Master workbook) I am currently working on (Sorry I am not allowed to enclose this file on this forum as it contains smwht confidential data of my company). The second part is the VBA code you suggested.

    The first part of the code is working perfectly fine on my Master workbook. and the second part of the code is something I want to add additionaly to the mast workbook. But when I added the new code to the Master workbook, a compling error message poped up and I wasn't able to save the VBA code.

    I think its cuz I can only use one 'Worksheet_SelectionChange' excel event for each worksheet. And my new question here is if i can combine both codes I have attached above in one (same) worksheet.

    If I am not explaining clearly, then please let me know. I will post another excel example with more data

    So basically I have two separate VBA code here: The one below is the one that's already being used on my Master workbook:
    Please Login or Register  to view this content.
    And another VBA code is the one I want to add additionaly to my Master Workbook (but it uses the same excel event - workbook_selection change):
    Please Login or Register  to view this content.
    Cheers,

  6. #6
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: How to highlight an active row within a selected range in excel

    Hi jjin
    Yes there is only one Worksheet_SelectionChange Event hence your error.
    I have now achieved both bits of code working on the same sheet as requested.
    To do so I have had to ditch the conditional formatting approach.
    It was being triggered where the rows of the two ranges overlapped.
    I have coded it to work/appear the same so you shouldn't notice any difference.
    Let me know if this is any closer to your requirement.
    Barry

    jjin Target range 050113 v4 - Excel.xlsm

  7. #7
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: How to highlight an active row within a selected range in excel

    Its exactly how I wanted. You are the ledgend Barryleajo. Thanks m8

+ 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