• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Automatically filling 2nd Column based on Dropdown list selection

ken7ken7

New Member
Good evening
in sheet 1 I have a named range that is used as a drop-down list in column A on sheet 2.
The list is made up of named ranges in sheet 1 that are subcategories of the first named range. What I would like to do in VBA is after the selection is made in the column A from the drop-down list, column B auto fills with the values from the subcategories until a new value is chosen in column A or the entire subcategory named range is transferred to column B.
I don't know how to even start .
Thank you
 

Attachments

  • Book1.9.12.xlsm
    24.7 KB · Views: 4
Last edited:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Call copysubcat
End If
End Sub

Sub copysubcat()
    'Description:
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.EnableEvents = False
    Dim var As Variant
    Dim ws As Worksheet
    Dim i As Variant
    
    Set ws = Sheets("Sheet2")
    i = 1
    
    For Each mycell In ws.Range("A1:A500")
    
      
        If mycell.Value <> "" Then
            Worksheets("sheet1").Range(mycell.Value).copy Worksheets("sheet2").Cells(i, 2)
        ElseIf mycell.Value = "" And ws.Cells(i, 2) <> "" Then
            mycell.Value = ws.Cells(i - 1, 1)
        End If
        i = i + 1
    Next mycell
  
endmacro:
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    Application.EnableEvents = True
    
End Sub
 
Got it
Now I need to attach to button click so that the manual action is removed.
loop thru the named range category one by one and add subcategories then move to the next category etc until completed

Any hints?

Thank you
 

Attachments

  • Book1.9.12.xlsm
    20.5 KB · Views: 8
Back
Top