Hi, there
I developed a function to return a string. However, if I return the function value after the line below, it always comes out as #Value! in the location I am calling it. Any suggestions?
Function FindString() as String Selection.Find(What:=LatNow, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate FindString="MyString" END Function
Thanks in advance.
Regards,
Lily
Last edited by SpringLily; 01-10-2012 at 10:16 AM. Reason: Solved
If you are trying to use that function from the worksheet it will fail as you have code to activate the cell containing searched for text, which is not allowed from sheet functions.
How exactly are you using that function?
Hi, Andy
I used the function by the equation below for a cell:
=IF(INSomething<>"",INSomething,FindString)
where InSomething is a defined name and FindString is the function for finding the right information. The code for the function is listed above.
Thanks.
Regards,
Lily
As I said functions called from worksheets do not allow alteration or selection of other cells.
Apart from that in your function was does LatNow refer to?
What would the selection be referring to?
Why a udf function rather than using VLOOKUP or MATCH?
The code itself is rather long (>100 sentences). I only quoted the line which caused problem. LatNow is defined before the line. Shall I use a sub instead of a function?
If you are using from a cell it will need to be a function in order to return a value to the cell.
You can use the find function but not the .Activate part.
The reason for me to use .activate part it to get the row number of the searched results. Below are the two lines from my function.
how do I modify the code to make it work?Selection.Find(What:=LatNow, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate CurrentRow = ActiveCell.Row
Thanks.
Regards,
Lily
Note the Selection and Activecell references will also need to change in order for the code to work properly from worksheet.dim rngFind as range set rngFind = Selection.Find(What:=LatNow, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) CurrentRow = rngFind.Row
Thanks. It works! Regards, Lily
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks