Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Anthony
 
Posts: n/a
Default Macro script error - pls help !!

Hi,
A button on worksheet1 (mondays log) is selected by the user and he/she is
then asked which job they wish to print - on input that number is searched
for in column B of Monday's log and the contents of that row are copied and
pasted into row A2 of sheet2 (Formula).
The script I have been given below works almost perfectly apart from the
following errors.

in 'monday's log' row B8 has job number 1, row B9 has job number 23 and the
rest of the rows are blank (for the moment)

The user inputs job 1 to print outcome is perfect
The user inputs job 2 to print and job 23 is picked up and printed
The user inputs job 3 to print and job 23 is picked up and printed
The user inputs job 4 to print and 'zero' values are picked up and printed
any other number entered by the user works fine (ie the error is shown if no
job with the input number is found).

I don't understand why when job 2 is selected number 23 is selected and the
same for job 3, or why if job 4 is selected I get a page of 'zero' values

Can anybody solve this for me

here is the script I was given

Sub print_mon_jobcard()

Dim i As Integer
Dim iRow As Integer
Dim wks1 As Worksheet, wks2 As Worksheet, wks3 As Worksheet
Dim lLastRow As Long
On Error GoTo err_handler
Set wks1 = Worksheets("monday's log")
Set wks2 = Worksheets("formula")
Set wks3 = Worksheets("jobcard")
i = InputBox("Please enter the job number you wish to print a job card for")
iRow = Columns("B:B").Find _
(What:=i, _
After:=Range("B1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Row
Worksheets("monday's log").Activate
ActiveSheet.Cells(iRow, 1).EntireRow.Copy Destination _
:=Worksheets("formula").Cells(2, 1)

wks3.PrintOut preview:=True
Exit Sub

err_handler:
MsgBox "No job with the number " & i & " has been found, please try
again!"
End Sub

Many many thanks for any help

Anthony
  #2   Report Post  
Dave O
 
Posts: n/a
Default

Your code is currently structured to find the first 2 or 3 in the
search area- when it looks for 2 or 3 the first one encountered happens
to be the 23 entry. You can solve this by taking these steps:
1. MAKE A BACKUP OF YOUR DATA so you don't inadvertenly lose critical
information, and so you can revert to your original (albeit somewhat
flawed) version.
2. Where your code says
LookIn:=xlFormulas, _
LookAt:=xlPart, _


.... replace these lines with
LookIn:=xlValues, _
LookAt:=xlWhole, _

This causes the search to look for just the value 2 or just the value 3
and will not find the value 23, for instance.

See if the solves the zero values with option 4 problem- I don't have
an idea for that one, but it may be something specific to your data
rather than the code.

Cheers!!

  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

Maybe it's as simple as changing:
LookAt:=xlPart,
to
LookAt:=xlWhole,

If you want to look at the complete cell's value.



Anthony wrote:

Hi,
A button on worksheet1 (mondays log) is selected by the user and he/she is
then asked which job they wish to print - on input that number is searched
for in column B of Monday's log and the contents of that row are copied and
pasted into row A2 of sheet2 (Formula).
The script I have been given below works almost perfectly apart from the
following errors.

in 'monday's log' row B8 has job number 1, row B9 has job number 23 and the
rest of the rows are blank (for the moment)

The user inputs job 1 to print outcome is perfect
The user inputs job 2 to print and job 23 is picked up and printed
The user inputs job 3 to print and job 23 is picked up and printed
The user inputs job 4 to print and 'zero' values are picked up and printed
any other number entered by the user works fine (ie the error is shown if no
job with the input number is found).

I don't understand why when job 2 is selected number 23 is selected and the
same for job 3, or why if job 4 is selected I get a page of 'zero' values

Can anybody solve this for me

here is the script I was given

Sub print_mon_jobcard()

Dim i As Integer
Dim iRow As Integer
Dim wks1 As Worksheet, wks2 As Worksheet, wks3 As Worksheet
Dim lLastRow As Long
On Error GoTo err_handler
Set wks1 = Worksheets("monday's log")
Set wks2 = Worksheets("formula")
Set wks3 = Worksheets("jobcard")
i = InputBox("Please enter the job number you wish to print a job card for")
iRow = Columns("B:B").Find _
(What:=i, _
After:=Range("B1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Row
Worksheets("monday's log").Activate
ActiveSheet.Cells(iRow, 1).EntireRow.Copy Destination _
:=Worksheets("formula").Cells(2, 1)

wks3.PrintOut preview:=True
Exit Sub

err_handler:
MsgBox "No job with the number " & i & " has been found, please try
again!"
End Sub

Many many thanks for any help

Anthony


--

Dave Peterson
  #4   Report Post  
Anthony
 
Posts: n/a
Default

Dave,
thanks that seems to have done the trick - easy if you know how!!
Cheers
Anthony

"Dave O" wrote:

Your code is currently structured to find the first 2 or 3 in the
search area- when it looks for 2 or 3 the first one encountered happens
to be the 23 entry. You can solve this by taking these steps:
1. MAKE A BACKUP OF YOUR DATA so you don't inadvertenly lose critical
information, and so you can revert to your original (albeit somewhat
flawed) version.
2. Where your code says
LookIn:=xlFormulas, _
LookAt:=xlPart, _


.... replace these lines with
LookIn:=xlValues, _
LookAt:=xlWhole, _

This causes the search to look for just the value 2 or just the value 3
and will not find the value 23, for instance.

See if the solves the zero values with option 4 problem- I don't have
an idea for that one, but it may be something specific to your data
rather than the code.

Cheers!!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM
Macro Formula revision? Mark Excel Worksheet Functions 1 November 28th 04 01:43 AM
Macro for multiple charts JS Excel Worksheet Functions 1 November 19th 04 03:44 AM


All times are GMT +1. The time now is 07:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"