I've been searching the forum for a solution but what i've found doesnt seem to print anything. I'm using Excel 2010. I have a listbox which is filled by the following code. I have on the same userform a command button for print preview and one for print.That's it, no code for the command buttons. I want to print or print preview only the user selected results in the listbox.
Any suggestions are appreciated.
Thanks
Userform with listbox code:
Private Sub NewIDChkr()
'
Application.ScreenUpdating = False
Sheets("NewIDChkr").Visible = True
Sheets("NewIDChkr").Select
Range("A1:C1").Select
Selection.ClearContents
Range("A1").Select
On Error GoTo ErrorHandler
Workbooks.OpenText Filename:= _
Application.GetOpenFilename
ErrorHandler:
If Err.Number = 1004 Then
MsgBox "Import aborted"
Exit Sub
End If
If Range("A1").Value <> "Serial Number" Then
MsgBox "The file was not a scanned item list.", vbCritical & vbOK, "Incorrect File Type..."
ThisWorkbook.Activate
Sheets("NewIDChkr").Visible = False
Exit Sub
End If
On Error GoTo 0
Range("A:C").Select
Selection.Copy
Set myWb = ActiveWorkbook
ThisWorkbook.Activate
Sheets("NewIDChkr").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
myWb.Activate
ActiveWindow.Close
Columns("C:E").Select
Selection.EntireColumn.Hidden = False
Range("D1").Select
'Auto fill formulas
Sheets("NewIDChkr").Select
Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("D1").AutoFill Destination:=Range("D1" & LastRow)
Columns("D").Select
Selection.EntireColumn.Hidden = True
Columns("A:C").Select
ActiveWorkbook.Worksheets("NewIDChkr").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("NewIDChkr").Sort.SortFields.Add Key:=Range("B2:B9"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("NewIDChkr").Sort.SortFields.Add Key:=Range("C2:C9"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("NewIDChkr").Sort
.SetRange Range("A1:C9")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("F1:H1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("A1").Select
Columns("A").Select
Range("D1").Activate
Selection.AutoFilter
ActiveSheet.Range("$A$1:$D$30000").AutoFilter Field:=4, Criteria1:="0"
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range("C1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Selection.Copy
Range("F1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveSheet.Range("$A$1:$D$30000").AutoFilter Field:=4
Sheets("NewIDChkr").Visible = False
NewIDChkrForm.Show
End Sub


" & LastRow)
Reply With Quote
