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
Tabs and Dark Mode
cjc2112 in Discussions on
22 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
PacketMon Components are not loading in WAC 1909
HotCakeX in Windows Admin Center on
2 Replies