excel - VBA: How to display a cell value by its defined name? -
i have defined name particular column in worksheet. how display cell value defined name?
i've tried these:
public sub test() dim r range set r = thisworkbook.names("somename").referstorange msgbox cstr(r.value) end sub
but run-time error occured "type mismatch" (error code: 13).
what's wrong code? actual data type of referstorange.value?
the documentation says referstorange returns range object, seems differ range object returned activecell, because i've no problem following code:
msgbox cstr(activecell.value)
i've been using excel 2003
referstorange return range object. assume you're getting type mismatch on cstr line. if range has multiple cells, value property returns variant array. in immediate window (control+g in vbe).
?typename(thisworkbook.names("somerange").referstorange) range ?typename(thisworkbook.names("somerange").referstorange.value) variant()
the cstr function can't handle array argument , that's why you're getting error. can particular cell in range, first cell, this
thisworkbook.names("somerange").referstorange(1).value
or loop through them fink suggests.
Comments
Post a Comment