Dim a Variable in Excel VBA

Occasional Visitor

Can I refer to a cell value/text for "dimming" a variable name, instead of typing it manually?

Something like this: "Dim & Range("A1").Text & as Variant", where A1 contains "myText".

Thank you in advance. Regards.

1 Reply



In VBA, if you want to refer the cell's value/text in the code, you can do this!

But you need to declare the Variable name as follows:

Dim Ce11_A1 As Variant


Then assign the cell range to the variable you just declared:

Cell_A1 = Range("A1")

So that you got the value/text of cell A1 stored in the variable Cell_A1.


After that, you can use this variable as you want in the code.



Sub test()
    Dim Ce11_A1 As Variant
    Cell_A1 = Range("A1")
    MsgBox Cell_A1
End Sub


Hope that helps

Related Conversations
vba sending email w/ attachment
katrina bethea in Excel on
7 Replies
Need some help with my Vlookup or a new idee
Jim Brastad in Excel on
5 Replies
VBA - Splitting worksheet by Dept
Zia Siddique in Excel on
12 Replies
Userform Listbox HELP
R3d3mpt10n in Word on
1 Replies