Steve Brown
asked on
Excel Function works on one sheet but not another
I have written a short function in Excel to find a number in a range in column AZ and return the row number. If the number is not found in then finds the next number following. So if the list contains 070, 071, 073 then looking for 070 would find the row for 070 whereas looking for 072 would return the row for 073. There is a similar function to work in reverse, so if the list contains 070, 071, 073 then looking for 073 would find the row for 073 whereas looking for 072 would return the row for 071. The function works fine on the worksheet where I created it, but will not return a value when called from a different worksheet. The function code is:
Function Start_Range(StartNum As String, CC As String)
Dim Search_String As String
Dim SearchNum As Integer
SearchNum = Val(StartNum)
Search_String = Format(CStr(SearchNum), "000") + CC
Do While IsNumeric(Application.Matc h(Search_S tring, Worksheets("RDB1CY").Range ("AZ:AZ"), 0)) = False
SearchNum = SearchNum + 1
Search_String = Format(CStr(SearchNum), "000") + CC
Loop
Start_Range = Application.Match(Search_S tring, Range("AZ:AZ"), 0)
End Function
When called from Worksheet RDB1CY the function operates as expected. When it is called from any other worksheets it returns #N/A.
Can anybody point me to where I am going wrong?
Function Start_Range(StartNum As String, CC As String)
Dim Search_String As String
Dim SearchNum As Integer
SearchNum = Val(StartNum)
Search_String = Format(CStr(SearchNum), "000") + CC
Do While IsNumeric(Application.Matc
SearchNum = SearchNum + 1
Search_String = Format(CStr(SearchNum), "000") + CC
Loop
Start_Range = Application.Match(Search_S
End Function
When called from Worksheet RDB1CY the function operates as expected. When it is called from any other worksheets it returns #N/A.
Can anybody point me to where I am going wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Don't worry it happens sometime with everyone.
Glad you identified the error in your code and you will remember not to repeat the same mistake in your future codes.
Bottom Line: Mistakes are important to learn to do things better in future. :)
Glad you identified the error in your code and you will remember not to repeat the same mistake in your future codes.
Bottom Line: Mistakes are important to learn to do things better in future. :)
ASKER
Note to self, don't try writing code at 22:00!!