VBA Excel: How to pass one parameter of different types to a function (or cast Int/String to Range)? -


i'm writing vba functions in excel compute word values , cross sums of input.

i'm passing input public function cross_sum(myrange range) integer them take cell references input, e.g. =cross_sum(a1). works fine.

however when try chain 2 functions =cross_sum(word_value(a1)) run th value error because word_value() returns integer value , not range cross_sum() set expect. did not find way cast integer (or string) range.

as excel's built-in functions support chaining range input wonder how. unfortunately first vba project wonder if , how cast or type choose working both ways.

any pointers appreciated!

tia, jbq

you can pass variant function , function can determine type of input:

public function inputs(v variant) string     if typename(v) = "range"         msgbox "you gave me range"     else         msgbox "you gave me string"     end if     inputs = "done" end function  sub main()     dim st string     dim rng range     st = "a1"     set rng = range(st)     x = inputs(st)     x = inputs(rng) end sub 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -