Bayport_Mama
New Member
- Joined
- Sep 8, 2022
- Messages
- 13
- Office Version
- 365
- Platform
- Windows
Hello!
I've searched high and low across multiple forums for this specific answer, but I can't seem to find it based on cell value. I can find the VBA code for ALL worksheet names to be listed in the ListBox, but not specific ones based on cell value to be used as selections for printing.
Here's what I have so far:
I have 2 Comboboxes within my worksheet, which are populated by a named range.
- cbAccountType listfillrange = Account_Type, with linkedcell of A2 for selection
-cbServiceSchedule listfillrange = Service_Schedule with linkedcell of A3 for selection
I then use the Filter function within A4 to populate the appropriate worksheet names
=IF(OR($A$2="Select",$A$3="Select"),"",FILTER(Lists!BO:BO,(Lists!BM:BM=$A$3)*(Lists!BN:BN=$A$4),"")) (a range is found on the Lists worksheet within columns BM:BO)
This filtered range is then named "Worksheets"
From there, I have Listbox1 which uses the listfillrange of "Worksheets". Listbox1 is also setup to MultiSelectExtended to be able to select multiple sheets
This all works perfectly until I want to print preview the appropriate sheets that are selected. I had found VBA code to use on a Command Button when clicked, but it's for all worksheets within the workbook, which I don't want. For reference, this is what I used to pull all worksheet names into the Listbox and print from there:
How can I change this code to recognize the selected items in my Listbox, that was populated from a named range, and select those worksheets to combine into a single document for Print Preview?
Sorry if I missed some pertinent information. I'm fairly new at posting within the boards. Let me know if you need any additional info!
I've searched high and low across multiple forums for this specific answer, but I can't seem to find it based on cell value. I can find the VBA code for ALL worksheet names to be listed in the ListBox, but not specific ones based on cell value to be used as selections for printing.
Here's what I have so far:
I have 2 Comboboxes within my worksheet, which are populated by a named range.
- cbAccountType listfillrange = Account_Type, with linkedcell of A2 for selection
-cbServiceSchedule listfillrange = Service_Schedule with linkedcell of A3 for selection
I then use the Filter function within A4 to populate the appropriate worksheet names
=IF(OR($A$2="Select",$A$3="Select"),"",FILTER(Lists!BO:BO,(Lists!BM:BM=$A$3)*(Lists!BN:BN=$A$4),"")) (a range is found on the Lists worksheet within columns BM:BO)
This filtered range is then named "Worksheets"
From there, I have Listbox1 which uses the listfillrange of "Worksheets". Listbox1 is also setup to MultiSelectExtended to be able to select multiple sheets
This all works perfectly until I want to print preview the appropriate sheets that are selected. I had found VBA code to use on a Command Button when clicked, but it's for all worksheets within the workbook, which I don't want. For reference, this is what I used to pull all worksheet names into the Listbox and print from there:
VBA Code:
Sub PrintForms()
Dim i As Long, c As Long
Dim SheetArray() As String
With ActiveSheet.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
ReDim Preserve SheetArray(c)
SheetArray(c) = .List(i)
c = c + 1
End I
Next i
End With
Sheets(SheetArray()).PrintPreview
End Sub
How can I change this code to recognize the selected items in my Listbox, that was populated from a named range, and select those worksheets to combine into a single document for Print Preview?
Sorry if I missed some pertinent information. I'm fairly new at posting within the boards. Let me know if you need any additional info!