excel - calling a function to return an array - type mismatch -
i have custom type shown below,
public type typefieldcolumn icol integer drow double end type
i have following sub routine
private sub populateworksheet() dim wsts worksheet dim clsdata new clsdatabase dim rsts new adodb.recordset dim fields() typefieldcolumn set wsts = thisworkbook.sheets(somename) set rsts = clsdata.somemethod() fields = findfactorcolumns(rsts, wsts) end sub
which calls function below
private function findfactorcolumns(rsts adodb.recordset, wsts worksheets) typefieldcolumn() dim integer dim index integer dim factorname string dim flds() typefieldcolumn redim flds(1 rsts.fields.count - 1) = 1 rsts.fields.count - 1 factorname = rsts.fields(i).name index = mapbloombergindextofactorname(factorname) if index > 0 factorname = pmap(index).mapname flds(i).icol = application.worksheetfunction.match(factorname, wsts.range("1:1"), 0) next findfactorcolumns = flds end function
i run time error of type mismatch on line fields = findfactorcolumns(rsts, wsts) - don't understand why though?
only writing save @rory time, answer.
the type mismatch occurred because wsts, saved single worksheet in populate worksheet sub, declared multiple worksheets in findfactorcolumn function.
because error line occured @ function call, @rory able determine type mismatch looking @ type of variables used in function , comparing them type of same variables when saved in sub.
Comments
Post a Comment