Mr Excelinator
New Member
- Joined
- Mar 4, 2014
- Messages
- 37
Hello everyone
Hope someone can help. In a bit of a head banger & up against a deadline.
I have a print macro which prints out all of the items selected in a list box loaded into a user form. Works perfectly. Now I need it to only print out the visible range based on filter results. Tried & tried & am struggling to get it to work. Any help at all would be massively appreciated.
I've included the code. Do shout if you need any clarification on the code.
Many thanks in advance!
Hope someone can help. In a bit of a head banger & up against a deadline.
I have a print macro which prints out all of the items selected in a list box loaded into a user form. Works perfectly. Now I need it to only print out the visible range based on filter results. Tried & tried & am struggling to get it to work. Any help at all would be massively appreciated.
I've included the code. Do shout if you need any clarification on the code.
Many thanks in advance!
Code:
Sub PrintAll(RptToPrint As Worksheet)
Dim NoPtnrs As Integer, c As Integer
Dim prng As String, pFrm As Object, PtnrRng As Range
'PtnrRng is used to resize the name range PartnerList so the userform listbox _
can be loaded without the blank spaces.
Set pFrm = New frmUpdPrint
prng = "PartnerList" ' Range with partners names for selection. Using pRng repeatedly _
is better than the more lengthy "PartnerList".
NoPtnrs = Range(prng).Rows.Count
Load pFrm
Set PtnrRng = Range(prng)
'.Offset(1, 0).Resize(Range(pRng).Rows.Count - 2, 1)
With pFrm
.btnPrintSlctd.Tag = "Y"
.lstPartners.Clear
'Remove For loop which loads the partners into the Userform listbox _
and use the below line which loads them all at once.
.lstPartners.List = PtnrRng.Value
'The below error handler is there incase the user has set the listbox _
selection to a blank field.
On Error Resume Next
.lstPartners.Selected(Range("myPtnrPrintIndex").Value - 2) = True
On Error GoTo 0
.StartUpPosition = 2
.Show
'Code to select partners to print and print/update using selections
If .btnPrintSlctd.Tag = "Y" Then
For c = LBound(.lstPartners.List) To UBound(.lstPartners.List)
If .lstPartners.Selected(c) Then
Range("myPtnrPrintIndex") = c + 1
RptToPrint.PrintOut
End If
Next c
End If
End With
Unload pFrm
Set pFrm = Nothing
Set PtnrRng = Nothing
End Sub