excel - VBA How do I get a cell value as module level constant? -


on module-level space, can use value constant directly.

private const aaa long = 3  sub test() debug.print aaa end sub 

however, cannot use cell value constant.

private const bbb long bbb = worksheets("sheet1").cells(1, 1)  sub test() debug.print bbb end sub 

i want define constant "bbb" on module-level space because value used on procedure.

please tell me solution of or substitute method.

why want define cell constant? have special reason this? it's nature, cell value can change - , isn't constant.

you wrap call read cell in function in module , call ever like.

public function getvalue() variant     getvalue = worksheets("sheet1").cells(1, 1).value end if 

but can call line direct call-site.

worksheets("sheet1").cells(1, 1).value  

if use function wrapper way, can set break point when call-site invokes call.

as bit of aside, can define property read cell , remove write part read when accessed code. there's nothing stop accessing cell shown above - unless lock cell protection...

hope helps.


Comments