Dialog Box with Multiple Items

M

mburkett

I would like to display a warning box with x number of variables. The
problem is if there is only 1 variable, and I write the dialog for say
10 total, the dialog box size looks odd. I would like to step through
10 variables and only put the ones that are not null in the dialog
box. Below is an example of how I am doing it now. The example below
has 3 variables but I would like to display the dialog box with only 1
variable if the other 2 are blank.

Sheets("Sheet1").Select
Range("b8").Select
trd1 = Selection.Value
Range("b9").Select
trd2 = Selection.Value
Range("b10").Select
trd3 = Selection.Value
Range("b11").Select

Msg = "Warning:" & Chr(10) & Chr(10) + trd1 & Chr(10) + trd2 & Chr(10)
+ trd3 ...
Title = " Pending FI Trades"
Message = MsgBox(Msg, Style, Title)
 
J

Jennifer

I would like to display a warning box with x number of variables. The
problem is if there is only 1 variable, and I write the dialog for say
10 total, the dialog box size looks odd.  I would like to step through
10 variables and only put the ones that are not null in the dialog
box. Below is an example of how I am doing it now. The example below
has 3 variables but I would like to display the dialog box with only 1
variable if the other 2 are blank.

Sheets("Sheet1").Select
 Range("b8").Select
    trd1 = Selection.Value
     Range("b9").Select
    trd2 = Selection.Value
     Range("b10").Select
    trd3 = Selection.Value
     Range("b11").Select

Msg = "Warning:" & Chr(10) & Chr(10) + trd1 & Chr(10) + trd2 & Chr(10)
+ trd3 ...
    Title = "         Pending FI Trades"
    Message = MsgBox(Msg, Style, Title)

I would set up the Msg variable like this:

Dim Msg as String
Dim X as Integer

Sheets("Sheet1").Select
Msg = "Warning:" & Chr(10) & Chr(10)

For X = 8 to 11 Step 1
Range("b" & X).Select
If Selection.Value <> "" Then
Msg = Msg & Selection.Value & Chr(10)
End If
Next X
 
P

Patrick Molloy

WITH Sheets("Sheet1")
Msg = "Warning:" & Chr(10) & Chr(10)
For X = 8 to 11
IF .Cells(X,"b").Value <> "" Then
Msg = Msg & .Cells(X,"b").Value & Chr(10)
End If
Next X
END WITH

OR

msg = "Warning:" & Chr(10) & Chr(10)
For Each Cell In Sheets("Sheet1").Range("B5,G7,K5:M5")
If Cell.Value <> "" Then
msg = msg & Cell.Value & Chr(10)
End If
Next
MsgBox msg
 

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

Top