+ Reply to Thread
Results 1 to 6 of 6

Thread: Hyperlink, Macro and Filtering all in one

  1. #1
    Registered User
    Join Date
    10-22-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Hyperlink, Macro and Filtering all in one

    Hi,

    I have a spreadsheet with Dept ID# in one column and a count of employees in that department in a second column on one tab. On another tab, I have employee details by dept. For example, let's say dept #1040 has a count of 3 emps on the first tab. The user would then click the the other tab, which will show all data, but he/she can then filter by the Dept # to pull up all 3 records.

    Now for the programming part: On the first tab, I want to create hyperlinks for the counts, which, when clicked, will switch to the second tab, then filter by Dept# to display all emp records related to that Dept#. Attached is a sample spreadsheet...

    My initial thought was to use a macro, as I think formula doesn't have the ability to do something this complex, but if there is a more elegant way of doing this, I'm open to suggestions.

    Thanks in advance!
    Attached Files Attached Files

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Cochrane,Alberta
    MS-Off Ver
    XL 2003,2007,2010
    Posts
    6,843

    Re: Hyperlink, Macro and Filtering all in one

    Use this formula in B1 and copy it down

    =HYPERLINK("#Sheet2!A1",COUNTIF(Sheet2!$A$1:$D$22,Sheet1!A2))

    Place this code in Sheet1 Module

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        If Target.Column <> 2 Then Exit Sub
        Worksheets("Sheet2").Range("A1").AutoFilter Field:=1, Criteria1:=Target.Offset(0, -1)
    
    End Sub
    Attached Files Attached Files
    Last edited by davesexcel; 10-22-2010 at 09:01 PM.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Hyperlink, Macro and Filtering all in one

    Hello Dave,

    Just thinking that you can activate "Sheet2" in the Worksheet_SelectionChange event and eliminate the Hyperlink formulas.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Cochrane,Alberta
    MS-Off Ver
    XL 2003,2007,2010
    Posts
    6,843

    Re: Hyperlink, Macro and Filtering all in one

    Thanks Leith,
    Had hyperlink stuck in the head


    Placing this in B2 and dragged down,
    =COUNTIF(Sheet2!$A$2:$A$10,Sheet1!A2)

    Then
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        If Target.Count > 1 Then Exit Sub
        If Target.Column <> 2 Then Exit Sub
        Worksheets("Sheet2").Activate
        Worksheets("Sheet2").Range("A1").AutoFilter Field:=1, Criteria1:=Target.Offset(0, -1)
    
    End Sub
    Does the exact same thing.
    Attached Files Attached Files
    Last edited by davesexcel; 10-22-2010 at 09:39 PM.

  5. #5
    Registered User
    Join Date
    10-22-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Hyperlink, Macro and Filtering all in one

    Thanks for the response! I'll give it a try later today and let you know how it goes.

  6. #6
    Registered User
    Join Date
    10-22-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Thumbs up Re: Hyperlink, Macro and Filtering all in one

    It worked! I copied the code and tweaked it a bit to fit the actual spreadsheet, which is MUCH bigger, and it worked!! Thanks for your help on this. [EOM]

+ 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.2.0