Auto MsgBox when Excel file is opened and a condition is met

MilesToGoBeforeISleep

I suspect this is a pretty easy answer but I'm new to VBA and trying to generate a msgbox when I open my file and a certain condition is met. My code, as it currently stands, is:

Sub StopLossWarning()

    If Range("C4").Value < 30 Then

        MsgBox "Maximum allowable loss is at " & Range("C4").Value

    End If

End Sub

The Msgbox appears fine when I run the macro. I just need it to run once automatically when I open the file.

Stupid_Intern

Try this:

  1. Press Alt+F11 to open VBA Editor

  2. Double click on ThisWorkbook from Project Explorer

    Copy the below code and paste there.

    Private Sub Workbook_Open()
    Dim WK As Worksheet
    
    Set WK = Sheet1 'Change it to your sheet number.
    
    If WK.Range("C4").Value < 30 Then
      MsgBox "Maximum allowable loss is at " & WK.Range("C4").Value
    End If
    End Sub
    

Alternatively You can insert a new module and paste the code below there:

    Sub Auto_Open()
    Dim WK As Worksheet
    
    Set WK = Sheet1 'Change it to your sheet number.

    If WK.Range("C4").Value < 30 Then
      MsgBox "Maximum allowable loss is at " & WK.Range("C4").Value
    End If
    End Sub

Note: If you have multiple worksheet you may want to refer to ranges explicitly. Otherwise you may get undesired result

Reference

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Excel - Transposing Data into Rows when Condition Met

From Dev

comment out lines in a file when condition met

From Dev

Excel 2013 If Function calculates True when condition is not met

From Dev

Exported excel file from datagridview shows error when opened VB

From Dev

Update excel file when opened if a new version is available

From Dev

delete trigger when condition is met

From Dev

Add "?" to a string when a condition is not met

From Dev

Reset List When Condition Met

From Dev

second condition not being met when condition is called

From Dev

Evaluating condition continues when condition is not met

From Dev

When a .csv file is opened in excel and saved as an excel sheet .does it have the same properties as that of an original excel sheet?

From Dev

How to automatically replace Excel formula with value when date/time condition is met

From Dev

macro that auto-executes when sheet is opened

From Dev

Auto-Snap a Terminal (or Nautilus) when Opened

From Dev

Excel VBA To Add New Row If Condition Is Met

From Dev

Excel file generated by table2excel jQuery plugin throws error when opened

From Dev

Excel VBA Code to select opened Excel file

From Dev

how to auto save and close excel file when clicking hyperlink "send"

From Dev

Excel vba userform crashes excel when opened

From Dev

Auto-populate a worksheet if a condition is met in the previous sheet

From Dev

validate form using parsley when a condition is met

From Dev

Add values to dataframe when condition met in R

From Java

Filter out rows when condition is met with dplyr

From Dev

Using AWK To extract data when a condition is met?

From Dev

While Loop not Breaking when Condition is Met

From Dev

Check a box with jQuery when condition is met

From Dev

Highlighting an entire row when condition is met

From Dev

R Shiny conditionalPanel displays when condition is not met

From Dev

CanExecute() not enabling button when condition is met

Related Related

  1. 1

    Excel - Transposing Data into Rows when Condition Met

  2. 2

    comment out lines in a file when condition met

  3. 3

    Excel 2013 If Function calculates True when condition is not met

  4. 4

    Exported excel file from datagridview shows error when opened VB

  5. 5

    Update excel file when opened if a new version is available

  6. 6

    delete trigger when condition is met

  7. 7

    Add "?" to a string when a condition is not met

  8. 8

    Reset List When Condition Met

  9. 9

    second condition not being met when condition is called

  10. 10

    Evaluating condition continues when condition is not met

  11. 11

    When a .csv file is opened in excel and saved as an excel sheet .does it have the same properties as that of an original excel sheet?

  12. 12

    How to automatically replace Excel formula with value when date/time condition is met

  13. 13

    macro that auto-executes when sheet is opened

  14. 14

    Auto-Snap a Terminal (or Nautilus) when Opened

  15. 15

    Excel VBA To Add New Row If Condition Is Met

  16. 16

    Excel file generated by table2excel jQuery plugin throws error when opened

  17. 17

    Excel VBA Code to select opened Excel file

  18. 18

    how to auto save and close excel file when clicking hyperlink "send"

  19. 19

    Excel vba userform crashes excel when opened

  20. 20

    Auto-populate a worksheet if a condition is met in the previous sheet

  21. 21

    validate form using parsley when a condition is met

  22. 22

    Add values to dataframe when condition met in R

  23. 23

    Filter out rows when condition is met with dplyr

  24. 24

    Using AWK To extract data when a condition is met?

  25. 25

    While Loop not Breaking when Condition is Met

  26. 26

    Check a box with jQuery when condition is met

  27. 27

    Highlighting an entire row when condition is met

  28. 28

    R Shiny conditionalPanel displays when condition is not met

  29. 29

    CanExecute() not enabling button when condition is met

HotTag

Archive