VBA code crashing

nboyd1151

New Member
Joined
Feb 9, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
never coded before but eager to learn. There are a few things I want this code to do:

1. If the user input into B6 makes the value of K6 go above 655, pop up....that works fine
2. If the total value of B13 exceeds 100, pop up...that works fine
3. A value input into B9 should force B11 and B12 to zero. Also, a value input into B11 or B12 should also force B9 to zero. it's a safety measure to keep someone from mixing oxygen (B9) with methane (flammable B11) OR hydrogen (flammable B12)

the macro should run automatically any time there is a change to B5:B12

Code:

Private Sub worksheet_change(ByVal Target As Range)
Dim keycells As Range
Set keycells = Range("B5:B12")

If Range("k6").Value > 655 Then MsgBox "CO2 Vapor Pressure Exceeded, Reduce Fill Pressure"
If Range("B13").Value > 100 Then MsgBox "Percentage Exceeds 100%"
If Range("H11").Value > 0 And Range("H9").Value > 0 Then MsgBox "Danger, Fuel/Oxidizer Mixture"
End If

End Sub
 

Attachments

  • worksheet.JPG
    worksheet.JPG
    92.4 KB · Views: 3

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Give something like this a try.
VBA Code:
Private Sub worksheet_change(ByVal Target As Range)

If Not Intersect(Target, Range("B9")) Is Nothing Then
    If Target.Value > "" Then
        Application.EnableEvents = False
        Range("B11").Value = ""
        Range("B12").Value = ""
        Application.EnableEvents = True
    End If
End If
If Not Intersect(Target, Range("B11:B12")) Is Nothing Then
    If Target.Value > "" Then
        Application.EnableEvents = False
        Range("B9").Value = ""
        Application.EnableEvents = True
    End If
End If

If Range("k6").Value > 655 Then MsgBox "CO2 Vapor Pressure Exceeded, Reduce Fill Pressure"

If Range("B13").Value > 100 Then MsgBox "Percentage Exceeds 100%"

If Range("H11").Value > 0 And Range("H9").Value > 0 Then MsgBox "Danger, Fuel/Oxidizer Mixture"

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,096
Latest member
Anshu121

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