Macro to run a form control Drop down for all individual values in the dropdown

surya444

New Member
Joined
Dec 9, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I need to run a excel table that dynamically changes based on form control drop down selection. I want to run a macro that changes the dropdown and copy+paste my table else where for all values in the form control.

Can someone please help ?


from the pic: based on brand selection, the table gets updated.


Thank you!
 

Attachments

  • Capture222.PNG
    Capture222.PNG
    26.1 KB · Views: 11

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try this macro, after changing the sheet names, drop down name, table and destination cell to suit.

As written, the dropdown is named "Drop Down 1" on the sheet named "Sheet1"; the table is the first table on "Sheet1"; the table is copied and pasted to cell A1 on the sheet named "Sheet3".

VBA Code:
Public Sub Loop_Dropdown_Copy_Table_To_Other_Sheet()

    Dim brandDropdown As DropDown
    Dim table As ListObject
    Dim destCell As Range
    Dim i As Long
    
    Set brandDropdown = Worksheets("Sheet1").Shapes("Drop Down 1").OLEFormat.Object

    Set table = Worksheets("Sheet1").ListObjects(1)
    
    Set destCell = Worksheets("Sheet3").Range("A1")
    
    For i = 1 To brandDropdown.ListCount
        brandDropdown.ListIndex = i
        With destCell
            table.Range.Copy
            .PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        End With
    Next

    Application.CutCopyMode = False
    
End Sub
 
Upvote 0
Hi John,

I made some changes in the code and it works 90% of the requirement :)
Except that the values are replaced by the last 'value' in drop-down. how can the code be modified to see that with every change in the drop down, the range is copied and pasted beneath the previous results?

Thank you,
Surya


Public Sub Loop_Dropdown_Copy_Table_To_Other_Sheet()

Dim brandDropdown As DropDown
Dim strtcell As Range
Dim destCell As Range
Dim sht As Excel.Worksheet
Dim i As Long

Set brandDropdown = Worksheets("Brand - ADS Aug'23").Shapes("Drop Down 26").OLEFormat.Object

Set strtcell = Worksheets("Brand - ADS Aug'23").Range("E23:AG36")

For i = 1 To brandDropdown.ListCount
brandDropdown.ListIndex = i

Set destCell = Worksheets("Sheet10").Range("A1")


With destCell
strtcell.Copy
.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With
Next

Application.CutCopyMode = False

End Sub
 
Upvote 0
Except that the values are replaced by the last 'value' in drop-down. how can the code be modified to see that with every change in the drop down, the range is copied and pasted beneath the previous results?
Add this before the End With:
VBA Code:
        Set destCell = destCell.Offset(strtcell.Rows.Count + 1)
 
Upvote 0

Forum statistics

Threads
1,215,103
Messages
6,123,108
Members
449,096
Latest member
provoking

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top