IF then statments

kchapm02

New Member
Joined
Oct 9, 2006
Messages
1
I am trying to search a colum for a number if the text is not there i want it to search for the next peace of number. The problem is that this number may or may not be on the source worksheet that it is searching if it not there i want it to skip it if it is there i want it to do the comands. Right now i get the error 91. Here is the code i have please help understand where i went wrong.

'1227
Windows("cont 10-02 run on 10-03-06.xls").Activate
Columns("A:A").Select
If Selection.Find(What:="1227", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate Then
ActiveCell.Offset(1, 1).Range("A1").Select
Selection.Copy
Windows("WE mm-dd-yy Contractor payroll 2006 b Template.xls").Activate
Range("K12").Select
ActiveSheet.Paste
Windows("cont 10-02 run on 10-03-06.xls").Activate
Cells.Find(What:="Shift Duration:", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(-1, 0).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
Windows("WE mm-dd-yy Contractor payroll 2006 b Template.xls").Activate
Range("M12").Select
ActiveSheet.Paste

End If

'1231
Windows("cont 10-02 run on 10-03-06.xls").Activate
Columns("A:A").Select
If Selection.Find(What:="1231", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate Then
ActiveCell.Offset(1, 1).Range("A1").Select
Selection.Copy
Windows("WE mm-dd-yy Contractor payroll 2006 b Template.xls").Activate
Range("K13").Select
ActiveSheet.Paste
Windows("cont 10-02 run on 10-03-06.xls").Activate
Cells.Find(What:="Shift Duration:", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(-1, 0).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
Windows("WE mm-dd-yy Contractor payroll 2006 b Template.xls").Activate
Range("M13").Select
ActiveSheet.Paste
End If
 

Some videos you may like

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Watch MrExcel Video

Forum statistics

Threads
1,114,041
Messages
5,545,679
Members
410,697
Latest member
srishtijain0708
Top