*Dear Gurus,* I'm trying to clean up my vba code for printing a named ranged. My problem is i want to ask the user to input a data to meet a criteria, and then if that while that criteria is true, it prints a certain range.
Here's my code, IT DOESNT SEEM TO PRINT THE RANGE SPECIFIED BY THE USER INPUT. My worksheet "PayDbase" contains ID No.[column A] , Name [ Column b], Section [column c]: My purpose of running this macro is to be able to print selected paylips based on the range input from user. Private Sub SelectedSlips() With Application .ScreenUpdating = False .DisplayAlerts = False End With Dim FindString As String Dim StartFrom As String Dim EndTo As String Dim Rng As Range Dim IDrng As Range Dim found As Boolean 'On Error GoTo Err_Execute FindString = InputBox("Enter a Payroll Period to Print") 'StartFrom = Worksheets("PayDbase").Range("P14").Value 'EndTo = Worksheets("PayDbase").Range("P17").Value If MsgBox(" Printer Properly Set-up?", vbYesNo + vbQuestion) = vbNo Then Exit Sub End If If Trim(FindString) <> "" Then With Sheets("PayDbase").Range("E:E") Set Rng = .find(What:=FindString, _ After:=.Cells(.Cells.Count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not Rng Is Nothing Then found = True Application.GoTo Rng, True StartFrom = InputBox("FROM WHAT ID-NO?") EndTo = InputBox("TO ID -NO?") 'Worksheets("PaySlip").Range("P17").Value = EndTo With Sheets("PayDbase").Range("A:A") Set IDrng = .find(What:=StartFrom, _ After:=.Cells(.Cells.Count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not IDrng Is Nothing Then Application.GoTo IDrng, True Else ' Select cell b7, first line of data computation sheet. Sheets("PayDbase").Activate 'selects the first IDno ActiveCell.Offset(0, -4).Select Selection.Copy Sheets("PAYSLIP").Select Range("D4").Select Selection.PasteSpecial paste:=xlPasteValues Application.CutCopyMode = False End If End With Do While found = True Worksheets("PayDbase").Select 'Application.Goto IDrng, True 'checks the next findstring if true ActiveCell.Offset(1, 4).Select If ActiveCell.Value <> FindString Then found = False MsgBox "Printing finished!", vbInformation Exit Do End If 'gets the next idno again ActiveCell.Offset(0, -4).Select Selection.Copy Sheets("PAYSLIP").Select Range("D$41").Select Selection.PasteSpecial paste:=xlPasteValues Application.CutCopyMode = False ActiveSheet.Calculate Range("B1:N68").Select Selection.PrintOut copies:=1 Sheets("PayDbase").Select ActiveCell.Offset(0, 4).Select ActiveCell.Offset(1, -4).Select Selection.Copy Sheets("PAYSLIP").Select Range("D4").Select Selection.PasteSpecial paste:=xlPasteValues Application.CutCopyMode = False With Selection .HorizontalAlignment = xlGeneral .VerticalAlignment = xlBottom End With Loop With Application .ScreenUpdating = True .DisplayAlerts = True End With Else MsgBox "ATTENTION! The PERIOD selected is not yet posted!", vbInformation End If 'Err_Execute: 'MsgBox "An error occurred." & vbCr & vbCr & "Error: " & Error$ End With End If End Sub -- ---------------------------------------------------------------------------------- Some important links for excel users: 1. Follow us on TWITTER for tips tricks and links : http://twitter.com/exceldailytip 2. Join our Facebook Group @ http://www.facebook.com/group.php?gid=287779555678 3. Excel tutorials at http://www.excel-macros.blogspot.com 4. Learn VBA Macros at http://www.quickvba.blogspot.com 5. Excel Tips and Tricks at http://exceldailytip.blogspot.com To post to this group, send email to excel-macros@googlegroups.com <><><><><><><><><><><><><><><><><><><><><><> HELP US GROW !! We reach over 6,800 subscribers worldwide and receive many nice notes about the learning and support from the group.Let friends and co-workers know they can subscribe to group at http://groups.google.com/group/excel-macros/subscribe