View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Doug Glancy Doug Glancy is offline
external usenet poster
 
Posts: 770
Default Line breaks in MsgBox concatenated variables

Sandy,

I noticed that mine prints a message even if there are no blanks and you got
a perfect answer from Tom anyways, but just for the record, this would fix
it:

If sStr < "" Then
MsgBox ("The blank cells a" & vbCrLf & sStr _
& vbCrLf & vbCrLf & "You must fill them in before proceeding!"), _
[vbOKOnly], ["Blank Cells!"]
End If

hth,

"Doug Glancy" wrote in message
...
Sandy,

This macro assumes your processing a selection, which is probably not the
case so adjust the range type as necessary:

Sub test()

Dim rCell As Range
Dim sStr As String
Dim lBlanksCount As Long
Dim sSeparator As String

lBlanksCount = 0

For Each rCell In Selection
If IsEmpty(rCell.Value) Then
lBlanksCount = lBlanksCount + 1
If lBlanksCount Mod 3 = 0 Then
sSeparator = vbCrLf
Else
sSeparator = " "
End If
sStr = sStr & " " & rCell.Address & sSeparator
End If
Next rCell

MsgBox ("The blank cells a" & vbCrLf & sStr _
& vbCrLf & vbCrLf & "You must fill them in before proceeding!"), _
[vbOKOnly], ["Blank Cells!"]

End Sub

hth,

Doug

"Sandy" wrote in message
...
Hello -

I have a msgbox that returns a concatenation of cell addresses that are
blank. My problem is there could be as many as 64 cell addresses
returned,
which would make the message box extend completely across the screen.
sStr
is the cell address. Here's the code:

MsgBox ("The blank cells a " & sStr _
& vbCrLf & vbCrLf & "You must fill them in before proceeding!"), _
[vbOKOnly], ["Blank Cells!"]

Is there any way I can get it to display three sStr and then do a vbCrLf,
then another three, etc.?

Any help will be greatly appreciated!
--
Sandy