make x as variable

rplim2016

Board Regular
Joined
Jun 28, 2016
Messages
76
Hello Excel Gurus,

Simple question: is it possible to make x variable using the function above? or anything text or numbers that I want to declare.

not working code

Option Explicit


Sub test()
Dim x As String
Debug.Print Evaluate("=CELL(""format"",x)")
End Sub

working code

Option Explicit


Sub test()
Dim x As String
Debug.Print Evaluate("=CELL(""format"",A2)")
End Sub


Thanks!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hello users,

I just figured it out. lol

Option Explicit


Sub test()
Dim X As String


X = "A2"
Debug.Print Evaluate("=CELL(""format""," & X & ")")
End Sub

Thanks
 
Upvote 0
Hi,
If you are using a varible then you need to fill that variable with a value.

Dim x as string

x = "My String"

But if you are using a string varible you should might consider to name the varible a little better. x, i, j, and so on are mostly used as integer varibles for loops better would be strMyText as string or something like that.
So basically what I am saying is when you declare a varible then specify the datatyp at the beginnen then if you get a runtime error you can spot the wrong declared varible a bit better.
Just a thought :)
 
Upvote 0
You haven't made your variable equal anything, it needs to be a cell reference.

Code:
Sub test()
Dim x As String
[COLOR="#FF0000"]x = Cells(2, "A").Address(0, 0)[/COLOR]
Debug.Print Evaluate("=CELL(""format"",[COLOR="#FF0000"]" & x & "[/COLOR])")
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top