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
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,215,593
Messages
6,125,715
Members
449,254
Latest member
Eva146

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top