I saw in an earlier post someone had suggested using On Error and I'm trying to apply it to my code.
I have a main sub routine (Route_Create) and two subroutines (Loader and Expiration)
In the Route_Create routine, I want to look in a specific column and see if the word Expire exists, if it does I want it to call the subroutine Expiration. If it does not then I want it to look in the same column and see if the words Add, Change or Replace exist, if it does then I want it to call the subroutine Loader.
The On Error seems like it might work but I'm don't understand the logic of it so I'm not coding it correctly. I thought an if/else would work better but I couldn't figure out that code.
The first part of the code starts after I find the specific column I need to search for Expire, Add, Replace or Change.
ActiveCell.Select
cellname = ActiveCell.Address
ColNumber = ActiveCell.Column
Rowstart = ActiveCell.row
Rowend = ActiveSheet.UsedRange.Rows.Count
If ColNumber > 26 Then x = 2 Else x = 1
ColLetter = Mid(cellname, 2, x)
' This is where I need the code to look for the words and decide if it should call a subroutine or not.
On Error Resume Next
Cells.Find(What:="Expire", After:=range(ColLetter & Rowstart, ColLetter & Rowend), SearchDirection:=xlPrevious).Select
On Error GoTo 0
Call Expiration
On Error Resume Next
Cells.Find(What:="Add", After:=range(ColLetter & Rowstart, ColLetter & Rowend), SearchDirection:=xlPrevious).Select
On Error GoTo 0
Call Loader
On Error Resume Next
Cells.Find(What:="Replace", After:=range(ColLetter & Rowstart, ColLetter & Rowend), SearchDirection:=xlPrevious).Select
On Error GoTo 0
Call Loader
Thanks for your help!
Frances
I have a main sub routine (Route_Create) and two subroutines (Loader and Expiration)
In the Route_Create routine, I want to look in a specific column and see if the word Expire exists, if it does I want it to call the subroutine Expiration. If it does not then I want it to look in the same column and see if the words Add, Change or Replace exist, if it does then I want it to call the subroutine Loader.
The On Error seems like it might work but I'm don't understand the logic of it so I'm not coding it correctly. I thought an if/else would work better but I couldn't figure out that code.
The first part of the code starts after I find the specific column I need to search for Expire, Add, Replace or Change.
ActiveCell.Select
cellname = ActiveCell.Address
ColNumber = ActiveCell.Column
Rowstart = ActiveCell.row
Rowend = ActiveSheet.UsedRange.Rows.Count
If ColNumber > 26 Then x = 2 Else x = 1
ColLetter = Mid(cellname, 2, x)
' This is where I need the code to look for the words and decide if it should call a subroutine or not.
On Error Resume Next
Cells.Find(What:="Expire", After:=range(ColLetter & Rowstart, ColLetter & Rowend), SearchDirection:=xlPrevious).Select
On Error GoTo 0
Call Expiration
On Error Resume Next
Cells.Find(What:="Add", After:=range(ColLetter & Rowstart, ColLetter & Rowend), SearchDirection:=xlPrevious).Select
On Error GoTo 0
Call Loader
On Error Resume Next
Cells.Find(What:="Replace", After:=range(ColLetter & Rowstart, ColLetter & Rowend), SearchDirection:=xlPrevious).Select
On Error GoTo 0
Call Loader
Thanks for your help!
Frances