Home

Dim a Variable in Excel VBA

Highlighted
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
Highlighted

Hi,

 

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.

 

Example

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

 

Hope that helps

Related Conversations
Paste in the Filter search field does not work
luka23 in Excel on
0 Replies
Adding new data to a pivot table
Anthony Blackburn in Excel on
1 Replies
how to search a list of items in a cell
shekharreddy in Excel on
0 Replies
town-level heat map in excel?
mcmct in Excel on
0 Replies
Multiple crashes of Excel
SCSVCS in Excel on
0 Replies
Search for multiple values
JKLOSS48 in Excel on
2 Replies