How to Show Several Lines in MsgBox

Gos-C

Active Member
Joined
Apr 11, 2005
Messages
258
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all,

Can someone please help me with the following code. I need to include the additional lines in the MsgBox.

Code:
Sub GetSampleSize()
Dim sSize As String

ThisWorkbook.FollowHyperlink Address:="http://www.raosoft.com/samplesize.html", NewWindow:=True
MsgBox "Enter the following numbers"

'I need to include the following lines in the message:
'
'    What margin of error can you accept?     2
'    What confidence level do you need?     95
'    What is the population size?    [Show value of cell EI1]
'    What is the response distribution?     2


    sSize = Application.InputBox(Prompt:="Please enter the number shown in the Sample Size Calculator for 'Your recommended sample size is'", _
          Title:="ENTER SAMPLE SIZE", Type:=1)
If sSize = vbNullString Then

           Exit Sub
End If

Range("EK1").Value = sSize

End Sub

Thank you,
Gos-C
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Maybe this kind of structure...
Code:
Sub MsgBoxTextDemo()
Dim MyText As String
MyText = "Enter the following numbers" & vbCr _
    & "    What margin of error can you accept?     2" & vbCr _
    & "    What confidence level do you need?     95" & vbCr _
    & "    What is the population size?    " & Range("I1").Value & vbCr _
    & "    What is the response distribution?     2"
MsgBox MyText
End Sub

Does that help?
 
Upvote 0
Yes, that works. Thank you very much, Ron.

cheers,
Gos-C
 
Upvote 0
I would like to have the texts aligned left and the numbers aligned right.

Can anyone help, please?

Gos-C
 
Upvote 0
Code:
Sub MsgBoxTextDemo()
  Dim MyText As String
  MyText = "Enter the following numbers" & vbLf & _
      "What margin of error can you accept?" & vbTab & 2 & vbLf & _
      "What confidence level do you need?" & vbTab & 95 & vbLf & _
      "What is the population size?" & vbTab & Range("I1").Value & vbLf & _
      "What is the response distribution?" & vbTab & 2
  MsgBox MyText
End Sub
 
Upvote 0
I would like to have the texts aligned left and the numbers aligned right.

Can anyone help, please?

Gos-C
Since message boxes use a proportional font, you'll face the same problem you'd face to get the numbers to align properly in a cell:
Experiment with tabs, spaces, other characters, etc. until the output "looks" right.
 
Upvote 0
Thank you, Kenneth and Ron. So, not even spaces can push them to the right. Right?
 
Upvote 0
OK . . . thank you, Kenneth. I will probably keep it as is.

Gos-c
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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