Print all items in a combo box

mbtaichi

Board Regular
Joined
Jan 5, 2016
Messages
71
Hi,
I have a combo box in cell B2 with a list of names.
Is there a Vba code to loop through the list, update the sheet from the combo box and print the worksheet.
I have over 100 names in the list and would like to run though the list updating the sheets and printing all.
Thanks
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
With a little guidance from https://stackoverflow.com/questions/51170356/excel-vba-for-each-loop-with-data-validation-lists
Code:
Sub LoopThroughDropdownAndPrint()
    Dim validationRange As Range
    Dim dropDownCell As Range
    
    Set dropDownCell = Range("B2")
   
    On Error Resume Next
    Set validationRange = Evaluate(dropDownCell.Validation.Formula1)
    On Error GoTo 0
    If Not validationRange Is Nothing Then
        'Validation list is based on a range
        Dim c As Range
        For Each c In validationRange
            dropDownCell.Value = c.Value
            ActiveSheet.PrintOut
        Next
    Else
         'Validation list is based on a fixed string
        Dim a As Variant, i As Integer
        a = Split(dropDownCell.Validation.Formula1, ",")
        For i = 0 To UBound(a)
            dropDownCell.Value = a(i)
            ActiveSheet.PrintOut
        Next
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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