VBA Message Box Help...

Golfpro1286

New Member
Joined
Aug 22, 2018
Messages
30
I am working on a code to fire a message box is a certain CheckBox133 is selected and if cell B225 is greater than $75,000. The code below works and message fires, the problem is that it fires any time a cell is changed. How do I limit this VBA to only changes to that checkbox and cell?


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Sheets("Commercial Loan Worksheet").CheckBox133.Value = True And Sheets("Commercial Loan Worksheet").Range("B225").Value >= 75000 Then
MsgBox "Alert: This loan is for business purpose and exceeds $75M. A loan memo is required for the file."
Sheets("Commercial Loan Memo").Visible = True
End If
End Sub


Thanks,

Adam
 
You could use this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim KyCell As Range
   If Target.CountLarge > 1 Then Exit Sub
   Set KyCell = Range("B225")
   On Error Resume Next
   Set KyCell = Union(KyCell, KyCell.Precedents, Range("[COLOR=#ff0000]B4[/COLOR]"))
   On Error GoTo 0
   If Not Intersect(Target, KyCell) Is Nothing Then
      If Me.CheckBox133.Value = True And Range("B225").Value >= 75000 Then
         MsgBox "Alert: This loan is for business purpose and exceeds $75M. A loan memo is required for the file."
         Sheets("Commercial Loan Memo").Visible = True
      End If
   End If
End Sub
Private Sub CheckBox133_Click()
   Range("[COLOR=#ff0000]B4[/COLOR]").Value = CheckBox133.Value
End Sub
Change the B4 in red to a cell of your choosing
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Ok, this should work for when B225 changes value
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim KyCell As Range
   If Target.CountLarge > 1 Then Exit Sub
   Set KyCell = Range("B225")
   On Error Resume Next
   Set KyCell = Union(KyCell, KyCell.Precedents)
   On Error GoTo 0
   If Not Intersect(Target, KyCell) Is Nothing Then
      If Me.CheckBox133.Value = True And Range("B225").Value >= 75000 Then
         MsgBox "Alert: This loan is for business purpose and exceeds $75M. A loan memo is required for the file."
         Sheets("Commercial Loan Memo").Visible = True
      End If
   End If
End Sub
For the checkbox, you would need to have code behind the check box

This worked perfectly, thank you so much for your help!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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