#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default on error

Hi
I have a macro with a selection.find when the code that it is trying to find
is not in selection its trapped by on error goto myerr this is in a for each
cell in range and next part of macro .it works first time error happens but
not 2nd?
the appropiate part of code is below any ideas?
Thanks
Tina
col = Range("myCodes").Column
firstRow = Range("MyCodes").Rows(1).Row
lastRow = Range("Mycodes").Rows(Range("MyCodes").Rows.Count) .Row
For i = lastRow To firstRow Step -1
MYCell = Cells(i, col)
myvalue = Cells(i, col).Offset(0, 6).Value - 1
If myvalue 0 Then
Cells(i, col).Offset(1, 0).Resize(myvalue).EntireRow.Insert
Cells(i, col).EntireRow.Copy
Cells(i, 1).Resize(myvalue + 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Windows("COMPONENTS.xls").Activate
Columns("A:A").Select
Selection.Find(What:=MYCell, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.Offset(0, 1).Resize(myvalue + 1, 4).Select
Selection.Copy
Windows("PLANNEDJOBS.xls").Activate
Cells(i, 12).Select
ActiveSheet.Paste
Else
Windows("COMPONENTS.xls").Activate
On Error GoTo MYERR
Columns("A:A").Select
Selection.Find(What:=MYCell, After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.Range("b1:e1").Copy
Windows("PLANNEDJOBS.xls").Activate
Cells(i, 12).Select
ActiveSheet.Paste
End If
MYERR: Windows("PLANNEDJOBS.xls").Activate
Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default on error

Dim rng as Range
col = Range("myCodes").Column
firstRow = Range("MyCodes").Rows(1).Row
lastRow = Range("Mycodes").Rows(Range("MyCodes").Rows.Count) .Row
For i = lastRow To firstRow Step -1
MYCell = Cells(i, col)
myvalue = Cells(i, col).Offset(0, 6).Value - 1
If myvalue 0 Then
Cells(i, col).Offset(1, 0).Resize(myvalue).EntireRow.Insert
Cells(i, col).EntireRow.Copy
Cells(i, 1).Resize(myvalue + 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Windows("COMPONENTS.xls").Activate
set rng = Columns("A:A").Find(What:=MYCell, After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
if not rng is nothing then
rng.Select
ActiveCell.Offset(0, 1).Resize(myvalue + 1, 4).Select
Selection.Copy
Windows("PLANNEDJOBS.xls").Activate
Cells(i, 12).Select
ActiveSheet.Paste
Else
Windows("COMPONENTS.xls").Activate
Set rng = Columns("A:A").Find(What:=MYCell, _
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
if not rng is nothing then
rng.select
ActiveCell.Range("b1:e1").Copy
Windows("PLANNEDJOBS.xls").Activate
Cells(i, 12).Select
ActiveSheet.Paste
End If
End If
Windows("PLANNEDJOBS.xls").Activate
Next

--
Regards,
Tom Ogilvy

"tina" wrote in message
...
Hi
I have a macro with a selection.find when the code that it is trying to

find
is not in selection its trapped by on error goto myerr this is in a for

each
cell in range and next part of macro .it works first time error happens

but
not 2nd?
the appropiate part of code is below any ideas?
Thanks
Tina
col = Range("myCodes").Column
firstRow = Range("MyCodes").Rows(1).Row
lastRow = Range("Mycodes").Rows(Range("MyCodes").Rows.Count) .Row
For i = lastRow To firstRow Step -1
MYCell = Cells(i, col)
myvalue = Cells(i, col).Offset(0, 6).Value - 1
If myvalue 0 Then
Cells(i, col).Offset(1, 0).Resize(myvalue).EntireRow.Insert
Cells(i, col).EntireRow.Copy
Cells(i, 1).Resize(myvalue + 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Windows("COMPONENTS.xls").Activate
Columns("A:A").Select
Selection.Find(What:=MYCell, After:=ActiveCell,

LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.Offset(0, 1).Resize(myvalue + 1, 4).Select
Selection.Copy
Windows("PLANNEDJOBS.xls").Activate
Cells(i, 12).Select
ActiveSheet.Paste
Else
Windows("COMPONENTS.xls").Activate
On Error GoTo MYERR
Columns("A:A").Select
Selection.Find(What:=MYCell, After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.Range("b1:e1").Copy
Windows("PLANNEDJOBS.xls").Activate
Cells(i, 12).Select
ActiveSheet.Paste
End If
MYERR: Windows("PLANNEDJOBS.xls").Activate
Next



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
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
Drillthrough MDX ERROR(Error.Number:-21467259) ?(urgent question) Microlong Excel Programming 2 March 4th 05 01:55 AM
Automation Error, Unknown Error. Error value - 440 Neo[_2_] Excel Programming 0 May 29th 04 05:26 AM
Error 50290: Error writing to Worksheet while using an ActiveX Control emblair3 Excel Programming 3 February 24th 04 06:03 PM


All times are GMT +1. The time now is 07:33 PM.

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"