Question : Message Boxs in VBA - adding parameters to the mes box

dear all,

i am trying to create a message box in vba i have this already:

MsgBox "WARNING: one of your inputs is over 500", vbExclamation + vbOKOnly

however i want the message box to tell me which values are over 500 i.e a1,a7 ( & so on )

furthermore i only want it to appear once, at the moment it will keep reappearing however many are greater than 500

so say if 5 values are greater than 500 it will show the mesage box 5 times where as i only want it showing once with the correct values showing on the meassage box i.e

wanring: values A1,A7,A9,A6,A0 are all greater than 500

how do i go about that

Regards

Rachel


Answer : Message Boxs in VBA - adding parameters to the mes box

If all your values are in column A we could use this:-

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
Sub Check500()
 
Dim iRow As String
Dim mTxt As String
 
iRow = 1
mTxt = ""
 
Do Until ActiveCell.Value = ""
    Range("A" & iRow).Select
    If ActiveCell.Value > 500 Then
        mTxt = mTxt & "A" & iRow & ", "
    End If
    iRow = iRow + 1
Loop
 
If Len(mTxt) > 0 Then
MsgBox "WARNING: one of your inputs is over 500" & Chr(10) & mTxt, vbExclamation + vbOKOnlym
End If
 
End Sub
Open in New Window Select All
Random Solutions  
 
programming4us programming4us