Command button to activate message box with warning report

RPM7

Board Regular
Joined
Nov 28, 2007
Messages
191
I've spent ages searching online for something that might help my application but I can't find anything.

I'm trying to create a command button that acts as a warning indicator for its respective worksheet.
Pressing the button will display a list of warnings present in the spreadsheet.

Basically, the cells within range "ab10:ab15" may contain a warning message relevant to that particular row.
i.e. If a warning in row 12 is present, AB12 will say "warning".
The adjacent cell in "ac10:ac15" will give the actual description of the error itself.

So, if any of the rows contains an error, the command button will say "Warning report" and turn red.
Pressing the command button will display a message box listing all of the errors present in range "ac10:ac15"
If no errors are present the command button will say "ok".

Is this possible?
All the posts I've seen so far don't show the cell value within a message box.
I should also mention, that my vba skills are very limited so I'm trying to decipher all the code I've seen so far and it has put me in circles.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
For anyone interested, I ended up leaving the button a normal colour and used a conditionally formatting cell above the button stating how many errors and warnings are in the spreadsheet.

Here's the vba I used to create multiple lines of messages based on the values of a specific range.

Private Sub CommandButton1_Click()

If Worksheets("sheet1").Range("G5").Value = "0 Errors & 0 Warnings" Then
CommandButton1.Caption = "Error Report"
MsgBox ("No Errors or Warnings Present")
Exit Sub
Else

MsgBox (Range("F6").Value & vbCrLf & "-------------------------" & vbCrLf & Range("BW14").Value & vbCrLf & vbCrLf & Range("BW15").Value & vbCrLf & vbCrLf & Range("BW16").Value & vbCrLf & vbCrLf & Range("BW17").Value & vbCrLf & vbCrLf & Range("BW18").Value & vbCrLf & vbCrLf & Range("BW19").Value & vbCrLf & vbCrLf & Range("BW20").Value & vbCrLf & vbCrLf & Range("BW21").Value & vbCrLf & vbCrLf & Range("BW22").Value & vbCrLf & vbCrLf & Range("BW23").Value & vbCrLf & vbCrLf & Range("BW24").Value & vbCrLf & vbCrLf & Range("BW25").Value & vbCrLf & vbCrLf & Range("BW26").Value & vbCrLf & vbCrLf & Range("BW27").Value & vbCrLf & vbCrLf & Range("BW28").Value & vbCrLf & vbCrLf & Range("BW29").Value & vbCrLf & vbCrLf & Range("BW30").Value), , "Error Report"

End If
End Sub

Its pretty crude, but it worked for me.
 
Upvote 0
For anyone interested, I ended up leaving the button a normal colour and used a conditionally formatting cell above the button stating how many errors and warnings are in the spreadsheet.

Here's the vba I used to create multiple lines of messages based on the values of a specific range.



Its pretty crude, but it worked for me.
Hi RPM7,

I'm still not too sure about the changing button colour however this code basically does what you describe for the message box part in slightly tidier code if you are interested:

Rich (BB code):
Sub WarningMessage()
Dim Cell As Range, cRange As Range, Warning As String


Set cRange = ActiveSheet.Range("AB10:AB15")


If Application.WorksheetFunction.CountIf(cRange, "Warning") = 0 Then
    MsgBox "No Errors or Warnings Present", vbOKOnly, "Error Report"
Else
    Warning = ""
    For Each Cell In cRange
        If Cell.Value = "Warning" Then
            Warning = Warning & Cell.Offset(0, 1).Value & vbCr
        End If
    Next Cell
    MsgBox Warning, vbOKOnly, "Error Report"
End If


End Sub
 
Upvote 0
Code:
Private Sub CommandButton1_Click()
CommandButton1.BackColor = RGB(255, 0, 0)
End Sub
 
Last edited:
Upvote 0
Code:
Private Sub CommandButton1_Click()
CommandButton1.BackColor = RGB(255, 0, 0)
End Sub
In which case, try this out:

Code:
Private Sub CommandButton1_Click()
Dim Cell As Range, cRange As Range, Warning As String


Set cRange = ActiveSheet.Range("AB10:AB15")


If Application.WorksheetFunction.CountIf(cRange, "Warning") = 0 Then
    CommandButton1.BackColor = RGB(146, 208, 80)
    CommandButton1.Caption = "No Errors - Check Again"
    MsgBox "No Errors or Warnings Present", vbOKOnly, "Error Report"
Else
    Warning = ""
    For Each Cell In cRange
        If Cell.Value = "Warning" Then
            Warning = Warning & Cell.Offset(0, 1).Value & vbCr
        End If
    Next Cell
    CommandButton1.BackColor = RGB(255, 0, 0)
    CommandButton1.Caption = "Errors Found! - Check Again"
    MsgBox Warning, vbOKOnly, "Error Report"
End If


End Sub
 
Upvote 0

Forum statistics

Threads
1,216,109
Messages
6,128,880
Members
449,477
Latest member
panjongshing

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top