message box

Paul B

Well-known Member
Joined
Feb 15, 2002
Messages
577
Can a message box display what’s in a cell? Example sub test() msgbox = A1 end sub I want the message box to display what’s in cell A1
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Yup,

You just need to reference the cell properly. e.g. cell "A1" on "Sheet1" would be:

<pre>
MsgBox Sheets("Sheet1").Range("A1").Value

</pre>


HTH
 
Upvote 0
Thanks, thought I could take it from here but, can it list a name range say if A1:A10 is named "My_list" can it show whats in A1:A10 in the message box?
 
Upvote 0
Using "A1:A10" as the range "My_List" this code will throw up a message box with the contents of these cells. I hope this is what you want.

<pre>

Public Sub main()

Dim NameSht As Worksheet
Dim NameRng As String
Dim Rng As Range
Dim Msg As String
Dim SubStr As String
Dim Index As Long

'Create space instring
Msg = Space(10000)

Index = 1

Set NameSht = Application.Names("My_List").RefersToRange.Worksheet
NameRng = Application.Names("My_List").RefersToRange.Address


For Each Rng In NameSht.Range(NameRng)
SubStr = Rng.Value & vbNewLine
Length = Len(SubStr)
' stuff the string inside the result variable
Mid$(Msg, Index, Length) = SubStr
' advance index
Index = Index + Length
Next

'Trim extra characters off of Msg
Msg = Left$(Msg, Index - 1)

MsgBox Msg

End Sub

</pre>
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

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