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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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