Hi there,
See if the attached workbook does what you need. It uses the following code:
Option Explicit
Sub PrintWorksheets()
Const sNUMBER_COLUMN As String = "A"
Const sSHEET_REPORT As String = "REPORT "
Const sNUMBER_CELL As String = "C7"
Const sWEEK_COLUMN As String = "L"
Const sSHEET_FORM As String = "FORM "
Const sWEEK_CELL As String = "C18"
Dim iNoOfReports As Integer
Dim rNumberCells As Range
Dim rNumberCell As Range
Dim rWeekCells As Range
Dim rWeekCell As Range
Dim wksReport As Worksheet
Dim wksForm As Worksheet
Dim vWeekNo As Variant
Dim iWeekNo As Integer
Dim rCell As Range
Set wksReport = ThisWorkbook.Worksheets(sSHEET_REPORT)
Set wksForm = ThisWorkbook.Worksheets(sSHEET_FORM)
With wksReport
Set rNumberCells = Intersect(.UsedRange, _
.Columns(sNUMBER_COLUMN))
Set rWeekCells = Intersect(.UsedRange, _
.Columns(sWEEK_COLUMN))
End With
Set rNumberCell = wksForm.Range(sNUMBER_CELL)
Set rWeekCell = wksForm.Range(sWEEK_CELL)
vWeekNo = InputBox("Specify the Week No", "Week Number")
If vWeekNo <> vbNullString Then
If IsNumeric(vWeekNo) Then
iWeekNo = CInt(vWeekNo)
If iWeekNo > 0 Then
iNoOfReports = 0
For Each rCell In rWeekCells.Cells
If rCell.Value = iWeekNo Then
rWeekCell.Value = iWeekNo
rNumberCell.Value = Intersect(rCell.EntireRow, _
rNumberCells).Value
wksForm.PrintOut
iNoOfReports = iNoOfReports + 1
End If
Next rCell
If iNoOfReports > 0 Then
MsgBox iNoOfReports & " reports printed for Week No " & _
iWeekNo, vbInformation, "Reports printed"
Else: MsgBox "No records located for Week No " & iWeekNo, _
vbInformation, "No records located"
End If ' If iNoOfReports > 0
Else: MsgBox "Invalid Week No", vbExclamation
End If ' If iWeekNo > 0
Else: MsgBox "You must specify a numeric value", vbCritical, "Invalid input"
End If ' If IsNumeric(vWeekNo)
End If ' If vWeekNo <> vbNullString
End Sub
The highlighted values can be changed to suit your own requirements.
Hope this helps - please let me know how you get on.
Regards,
Greg M
Bookmarks