Serving the Quantitative Finance Community

 
User avatar
sml31
Topic Author
Posts: 0
Joined: July 14th, 2002, 3:00 am

VBA Code problem

September 18th, 2002, 3:24 pm

Hi there,I've sat in front of this one for a while but can't see what is wrong. I get a type mismatch error.Any suggestions?Dim firstCocoaRow As Long firstCocoaRow = Worksheets("Risks").Cells.Find(What:="CC", LookIn:=xlValues, SearchOrder:=xlByColumns, SearchDirection:=xlNext).RowAny help appreciatedSteve
 
User avatar
audetto
Posts: 0
Joined: March 12th, 2002, 4:08 pm

VBA Code problem

September 18th, 2002, 3:38 pm

no errors if it can find CC, but if there's no CC you shouldDIM resset res = worksheets(..).cells.find(..)and test for res not being Nothing... then you can get Row propertybye
 
User avatar
sml31
Topic Author
Posts: 0
Joined: July 14th, 2002, 3:00 am

VBA Code problem

September 19th, 2002, 9:09 am

The problem seems to be when I call the function that this code is written in from a cell, it falls over. Wheras if I call it otherwise, it is fine.
 
User avatar
Russell
Posts: 1
Joined: October 16th, 2001, 5:18 pm

VBA Code problem

September 19th, 2002, 2:32 pm

Steve,try debugging when the error message occurs and in the debug panel type:? typename(Worksheets("Risks").Cells.Find(What:="CC", LookIn:=xlValues, SearchOrder:=xlByColumns, SearchDirection:=xlNext).Row)This should shed some light on what is being returned!There is some difference between what you can do in code that is executed as part of a calculation (i.e. in a cell) and run via the macro tool. But mainly the difference is in what you are allowed to modify (i.e. cells other than the one calling the code).
 
User avatar
gregorios
Posts: 0
Joined: September 20th, 2002, 1:15 pm

VBA Code problem

September 20th, 2002, 1:40 pm

Hello,I think I've had this problem some time ago.If I understand correctly you are trying to call your VBA function from a cell.If my memory serves me right, I think the problem is as follows:When you hit the return key, after typing the formula name and arguments in the ActiveCell, this cell remains in 'edit' state until a value is returned from the function.In the meanwhile the Cells.Find method cannot operate as it needs all cells to be in idle state.Hope this helps.
 
User avatar
Russell
Posts: 1
Joined: October 16th, 2001, 5:18 pm

VBA Code problem

September 20th, 2002, 1:44 pm

Good spot gregorios!So make sure that the cell which contains your user defined function is NOT part of the range which you run the find method over.Good luck!
 
User avatar
sml31
Topic Author
Posts: 0
Joined: July 14th, 2002, 3:00 am

VBA Code problem

September 21st, 2002, 5:39 am

Thanks for all your help.