1

I was wondering if anybody could help me turn the below into a msg box. Basically i want it to first check whether any of the below range's say CHECK and if they do a msgbox will appear explaining which rule has been breached. I have had an attempt at creating the variable but not really sure how to put this into practice in a msgbox.

Sub ErrorMsgBox()

Dim Error1 As String
    If Range("DaisyFreshRule").Value = "CHECK" Then
    Error1 = "Daisy Fresh Rule"
Else
End If

Dim Error2 As String
    If Range("MigrationRule").Value = "CHECK" Then
    Error2 = "Migration Rule"
Else
End If

Dim Error3 As String
    If Range("ServiceCreditRule").Value = "CHECK" Then
    Error3 = "Service Credit Rule"
Else
End If

End Sub
Community
  • 1
  • 1
Peter Mogford
  • 478
  • 1
  • 4
  • 15

2 Answers2

6
Sub ErrorMsgBox()

  Dim Error As String: Error=""

  If Range("DaisyFreshRule").Value = "CHECK" Then
    Error = vbNewLine & "Daisy Fresh Rule"
  End If

  If Range("MigrationRule").Value = "CHECK" Then
    Error = Error & vbNewLine & "Migration Rule"
  End If

  If Range("ServiceCreditRule").Value = "CHECK" Then
    Error = Error & vbNewLine & "Service Credit Rule"
  End If

  If Error <> "" Then
    MsgBox "The following checks have been detected:" & Error
  End If

End Sub
Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
Amorpheuses
  • 1,403
  • 1
  • 9
  • 13
3

Give this a try

Sub ErrorMsgBox()
    Dim Err As String

    If UCase(Range("DaisyFreshRule").Value) = "CHECK" Then Err = Err & "Daisy Fresh Rule" & vbNewLine
    If UCase(Range("MigrationRule").Value) = "CHECK" Then Err = Err & "Migration Rule" & vbNewLine
    If UCase(Range("ServiceCreditRule").Value) = "CHECK" Then Err = Err & "Service Credit Rule" & vbNewLine

    If Not Err = vbNullString Then MsgBox prompt:=Err, Buttons:=vbCritical
End Sub
Tom
  • 9,725
  • 3
  • 31
  • 48