Forum Discussion
f_osolo75
Apr 01, 2023Copper Contributor
Excel
I have been trying to print a document that has a drop down list so that each an every list can get printed automatically , but to no avail. I need to print out only the selected range. What should I...
f_osolo75
Apr 02, 2023Copper Contributor
Thanks. How do I add a range argument to the PrintOut method?
NikolinoDE
Apr 02, 2023Platinum Contributor
Print by adding a range argument to the PrintOut method
You can use a loop to iterate through the items in the drop-down list and print the selected range for each item.
Here’s an example that assumes the drop-down list is a data validation list in cell A1 on Sheet1 and the range to print is B2:C3 on Sheet1.
Sub PrintDropDownList()
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
Dim val As Variant
Set ws = Worksheets("Sheet1")
Set rng = ws.Range("A1").Validation.Formula1
rng = Right(rng, Len(rng) - 1)
Set rng = ws.Range(rng)
For Each cell In rng.Cells
val = cell.Value
ws.Range("A1").Value = val
ws.Range("B2:C3").PrintOut
Next cell
End SubThis code sets the value of cell A1 to each item in the drop-down list and then prints the range B2:C3.
You can adjust the worksheet and range references to match your specific needs.
I hope this helps!