Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default help with error in code

I have the following code

Public Sub test()
Dim cfind As Range
Dim x As Range
Dim cell As Range
Dim myrange As Range
Worksheets("printing").Activate
Set myrange = Range(Range("a3"), Cells(Rows.Count, 1).End(xlUp))
For Each cell In myrange

Worksheets("planning").Activate
With Range("e3:e61")
Set cfind = .Cells.Find(what:=cell.Value, lookat:=xlWhole)

Set x = cfind.End(xlToLeft)

End With
Worksheets("printing").Activate
cell.Offset(0, 3) = x
line20:
Next cell
End Sub

It almost does the job however if the value in in worksheet("printing") is
not found then it stops and shows an error. I would like it not to show an
error but return a blank value into the the worksheet

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default help with error in code

'---------------------
Public Sub test()
Dim cfind As Range
Dim x As Variant
Dim cell As Range
Dim myrange As Range
Worksheets("printing").Activate
Set myrange = Range(Range("a3"), Cells(Rows.Count, 1).End(xlUp))
For Each cell In myrange

Worksheets("planning").Activate
With Range("e3:e61")
Set cfind = .Cells.Find(what:=cell.Value, lookat:=xlWhole)
If cfind Is Nothing Then
x = 0
Else
x = cfind.End(xlToLeft).Value
End If
End With
Worksheets("printing").Activate
cell.Offset(0, 3) = x
line20:
Next cell
End Sub
'---------------------

HTH
--
AP

"Paul" a écrit dans le message de
...
I have the following code

Public Sub test()
Dim cfind As Range
Dim x As Range
Dim cell As Range
Dim myrange As Range
Worksheets("printing").Activate
Set myrange = Range(Range("a3"), Cells(Rows.Count, 1).End(xlUp))
For Each cell In myrange

Worksheets("planning").Activate
With Range("e3:e61")
Set cfind = .Cells.Find(what:=cell.Value, lookat:=xlWhole)

Set x = cfind.End(xlToLeft)

End With
Worksheets("printing").Activate
cell.Offset(0, 3) = x
line20:
Next cell
End Sub

It almost does the job however if the value in in worksheet("printing") is
not found then it stops and shows an error. I would like it not to show an
error but return a blank value into the the worksheet



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default help with error in code

Thanks for your reply! I was wondering if you could help me further. I need
the formatting to also be copied, is this posible?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default help with error in code

Change

cell.Offset(0, 3) = x


to
cfind.End(xlToLeft).copy cell.offset(0,3)

if the source cell has a formula and you want to do values and formats

cfind.End(xlToLeft).copy
With cell.offset(0,3)
.pastespecial xlValues
.pastespecial xlFormats
End With



--
Regards,
Tom Ogilvy


"Paul" wrote in message
...
Thanks for your reply! I was wondering if you could help me further. I

need
the formatting to also be copied, is this posible?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default help with error in code

Answered in original thread.

--
Regards,
Tom Ogilvy


"Paul" wrote in message
...
I have the following code

Public Sub test()
Dim cfind As Range
Dim x As Range
Dim cell As Range
Dim myrange As Range
Worksheets("printing").Activate
Set myrange = Range(Range("a3"), Cells(Rows.Count, 1).End(xlUp))
For Each cell In myrange

Worksheets("planning").Activate
With Range("e3:e61")
Set cfind = .Cells.Find(what:=cell.Value, lookat:=xlWhole)

Set x = cfind.End(xlToLeft)

End With
Worksheets("printing").Activate
cell.Offset(0, 3) = x
line20:
Next cell
End Sub

It almost does the job however if the value in in worksheet("printing") is
not found then it stops and shows an error. I would like it not to show an
error but return a blank value into the the worksheet



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
Code error Tom Excel Programming 7 February 22nd 06 09:46 AM
Error Code 6 Dave Excel Programming 5 September 7th 05 07:12 PM
How can I still go to the error-code after a On Error Goto? Michel[_3_] Excel Programming 2 May 4th 04 04:21 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM
More to Error in code Julie Excel Programming 4 November 4th 03 06:10 PM


All times are GMT +1. The time now is 12:28 PM.

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

About Us

"It's about Microsoft Excel"