PRINTING ALL OPTIONS ON A DROP DOWN LIST

EMASOFT

New Member
Joined
Jun 24, 2024
Messages
10
Office Version
  1. 2021
recieve kind greetings
am tryin to print all options from a drop down menu the code is runnig well but then it goes ahead to print even the blank cell my code is

VBA Code:
Sub Iterate_Through_data_Validation()
    Dim xRg As Range
    Dim xCell As Range
    Dim xRgVList As Range
    Set xRg = Worksheets("RPT").Range("U13")
    Set xRgVList = Evaluate(xRg.Validation.Formula1)
    For Each xCell In xRgVList
        xRg = xCell.Value
        ActiveSheet.PrintOut
    Next
End Sub
 
Last edited by a moderator:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
How about checking if given entry is not empty? Like:
VBA Code:
For Each xCell In xRgVList
  if trim(xCell.Value)<>"" then
    xRg = xCell.Value
    ActiveSheet.PrintOut
  end if
Next
 
Upvote 1
thank you
how do i use the vba code? do i have to edit my already existing code? or delete and paste ths?
thank you for your help
 
Upvote 0
Replace the loop in your code. so the whole Sub will now look like:

VBA Code:
Sub Iterate_Through_data_Validation()
Dim xRg As Range
Dim xCell As Range
Dim xRgVList As Range
Set xRg = Worksheets("RPT").Range("U13")
Set xRgVList = Evaluate(xRg.Validation.Formula1)
For Each xCell In xRgVList
  if trim(xCell.Value)<>"" then
    xRg = xCell.Value
    ActiveSheet.PrintOut
  end if
Next
End Sub
 
Upvote 0
Solution
thank you so much
code works perfectly well
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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