A
Anthony
Hi,
I have the following code which has been very kindly donated to be.
it basicaly searches a row for the input number and returns all the data on
that row. It keeps doing this until the entire column has been searched for
the input number.
Can anybody tell me who to change the code so that once the macro is
selected it automaticaly picks up 'todays date' and searches for that/
ie so once selected a search is made for all previouys data entered today
and displayed elswhere.
Many thanks - and go easy with the novice!
Sub print_mon_jobcard()
Dim i As Integer
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFirst As Range
Dim rngDestination As Range
Dim rngAllRecords As Range
Dim wks1 As Worksheet, wks2 As Worksheet
'On Error GoTo err_handler
i = InputBox("Please enter the job number you wish to print a job card for")
Set wks1 = ThisWorkbook.Worksheets("adhoc database")
Set wks2 = ThisWorkbook.Worksheets("adhoc database")
On Error Resume Next
Set rngToSearch = wks1.Columns("a")
Set rngDestination = wks2.Cells(Rows.Count, "a").End(xlUp).Offset(15, 0)
Set rngFound = rngToSearch.Find _
(What:=i, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "No job with the number " & i & _
" has been found, please try again! "
Else
On Error GoTo err_handler
Set rngFirst = rngFound
Set rngAllRecords = rngFound
Do
Set rngAllRecords = Union(rngAllRecords, rngFound)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllRecords.EntireRow.Copy rngDestination
wks3.PrintOut
End If
Exit Sub
err_handler:
MsgBox Error, , "Err " & Err.Number
End Sub
I have the following code which has been very kindly donated to be.
it basicaly searches a row for the input number and returns all the data on
that row. It keeps doing this until the entire column has been searched for
the input number.
Can anybody tell me who to change the code so that once the macro is
selected it automaticaly picks up 'todays date' and searches for that/
ie so once selected a search is made for all previouys data entered today
and displayed elswhere.
Many thanks - and go easy with the novice!
Sub print_mon_jobcard()
Dim i As Integer
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFirst As Range
Dim rngDestination As Range
Dim rngAllRecords As Range
Dim wks1 As Worksheet, wks2 As Worksheet
'On Error GoTo err_handler
i = InputBox("Please enter the job number you wish to print a job card for")
Set wks1 = ThisWorkbook.Worksheets("adhoc database")
Set wks2 = ThisWorkbook.Worksheets("adhoc database")
On Error Resume Next
Set rngToSearch = wks1.Columns("a")
Set rngDestination = wks2.Cells(Rows.Count, "a").End(xlUp).Offset(15, 0)
Set rngFound = rngToSearch.Find _
(What:=i, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "No job with the number " & i & _
" has been found, please try again! "
Else
On Error GoTo err_handler
Set rngFirst = rngFound
Set rngAllRecords = rngFound
Do
Set rngAllRecords = Union(rngAllRecords, rngFound)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllRecords.EntireRow.Copy rngDestination
wks3.PrintOut
End If
Exit Sub
err_handler:
MsgBox Error, , "Err " & Err.Number
End Sub