Consulting

Results 1 to 3 of 3

Thread: VBA help in creating a dependent and source views

  1. #1
    VBAX Newbie
    Joined
    Jul 2019
    Posts
    2
    Location

    VBA help in creating a dependent and source views

    Hi Excel Experts,
    I'm looking for vba code for my below excel data. I couldn't figure out how to do it. Hope someone could help me
    I have Product and Categories data (2 columns). For each Product, it should show me its corresponding Categories and on click of category, it should show me corresponding products.

    Eg data:
    Product Category
    P1 C1
    P1 C2
    P2 C1
    P3 C1
    P3 C2
    P3 C3

    Output data:
    P1 C1 If I click on C1, it should show me P1,P2,P3
    ---C2 If I click on C2, it should show me P1,P3

    P2 C1 If I click on C1, it should show me P1,P2,P3

    P3 C1 If I click on C1, it should show me P1,P2,P3
    ----C2 If I click on C2, it should show me P1,P3
    ----C3 If I click on C3, it should show me P1,P2,P3
    Last edited by himajam; 07-31-2019 at 10:12 AM. Reason: spaces were not shown properly

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,872
    There is some built-in functionality for this; right-click on a cell and choose Filter|Filter by selected cell's value.
    You could automate it a bit with this in the sheet's code-module:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Columns("A:B")) Is Nothing Then
      If (Me.AutoFilterMode And Me.FilterMode) Or Me.FilterMode Then Me.ShowAllData
      Range("A1").CurrentRegion.Resize(, 2).AutoFilter Field:=Target.Column, Criteria1:=Target.Value
    End If
    End Sub
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Newbie
    Joined
    Jul 2019
    Posts
    2
    Location
    Hi p45cal (VBAX Guru) , Thanks a lot... It worked like a charm... Kudos to you... You have solved it just like that (minimal code).. Awesome

Posting Permissions

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