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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,213,552
Messages
6,114,278
Members
448,560
Latest member
Torchwood72

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