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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

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