How to Return Range value to message box

kmbrady

New Member
Joined
Aug 16, 2017
Messages
2
I have a text string stored in a cell that I need to show in a message box

Text is in cell 'e34' on sheet 'Tables'

I have also named cell 'e34' as 'TxT13'

If i refer to the cell as 'e34' this code works

Sub WITO()
If Sheets("Tables").Range("Prmt13") = "True" Then​
msg = Sheets("Tables").Range("e34").Value
MsgBox msg
End If​
End Sub

BUT
If I use the Range Name I get a blank message box

Sub WITO()
If Sheets("Tables").Range("Prmt13") = "True" Then​
msg = Sheets("Tables").Range("TxT13").Value
MsgBox msg
End If​
End Sub

I have attempted several variations but always get a blank message box,
' msg = Worksheets("Tables").Range("TxT13")
' msg = Sheets("Tables").Evaluate("TxT13")
' msg = Sheets("Tables").Range("TxT13").Value

Using the Range name does not return the text value to the message box. If I use the Name Manager to look at all my named ranges, the values are shown.

Suggestions?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
"TxT13" is not a valid Name. Excel should Autocorrect to "TxT13_"

Adjust your "msg" variable to match.
 
Upvote 0
"TxT13" is not a valid Name. Excel should Autocorrect to "TxT13_"

Adjust your "msg" variable to match.

Thanks for the tip, adding the underline worked.

What is interesting is I'm testing a named Range (Prmt13) for a 'True' value, and it works without the underline at the end.
If Sheets("Tables").Range("Prmt13") = "True" Then ....

Thanks again
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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