Newbie, msgbox

  • Thread starter Thread starter Bmj
  • Start date Start date
B

Bmj

Hi,

I want to display all the values from range H2:H8 in a msgbox, with a
linefeed between the values. How to do this??

Best Regards,
A newbie
 
Try:

Sub test()

Dim r As Range
Dim str As String

For Each r In Range("h2:h8")
str = str & r.Value & Chr(13)
Next

MsgBox str
End Sub
 
Try:

Dim cell As Range
Dim anyS
For Each cell In Range("H2:H8")
If anyS = "" Then
anyS = cell.Value
Else
anyS = anyS & Chr(13) & cell.Value
End If
Next
MsgBox anyS

Robert Flanagan
Macro Systems
Delaware, U.S. 302-234-9857
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel
 
Remove the IF

Dim cell As Range
Dim anyS
anyS = Range("H2")
For Each cell In Range("H3:H8")
anyS = anyS & vbCrLf & cell.Value
Next
MsgBox anyS

:-)
 
Perfecto!!! Thanx :-)))


Bob Phillips said:
Remove the IF

Dim cell As Range
Dim anyS
anyS = Range("H2")
For Each cell In Range("H3:H8")
anyS = anyS & vbCrLf & cell.Value
Next
MsgBox anyS

:-)

--

HTH

RP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top