|
-
Nov 9th, 2011, 09:29 PM
#1
Thread Starter
Junior Member
[RESOLVED] Print or print preveiw a listbox selection
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
-
Nov 10th, 2011, 05:26 AM
#2
Re: Print or print preveiw a listbox selection
in your command buttons try
vb Code:
Sheets("NewIDChkr").printpreview Sheets("NewIDChkr").printout
use code or vbcode tags when posting code
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 10th, 2011, 09:32 PM
#3
Thread Starter
Junior Member
Re: Print or print preveiw a listbox selection
I got your codes to work.
Any suggestions for printing only the user selected items?
Thanks Pete
-
Nov 11th, 2011, 03:49 AM
#4
Re: Print or print preveiw a listbox selection
Any suggestions for printing only the user selected items?
i have no idea what the selected items are, or what the code above has to do with the listbox
if you want people to read your code, edit your post and enclose the code in code or vbcode tags
possible copy the selected items to a new sheet, print the sheet, delete (or clear) the sheet
or use the printout method of a range object
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|