If multiple conditions are met then macro else do nothing

cs13 -  
f894009 Posted messages 17417 Registration date   Status Member Last intervention   -
Hello,

I would like to perform or not perform an action based on conditions being met or not.

That is to say:
if the last line of column C on Sheet2 is "moteur" and the value of C2 on my Sheet1 is > 0, then the result of C2 on Sheet1 = C2 - 1, otherwise do not execute the macros and display a message box "stock at zero".

I’m missing some things... The know-how, perhaps :-)

If Sheets("Sheet2").Range("C65536").End(xlUp) = "moteur" and Sheets("Sheet1").Range("C2") > 0 Then Sheets("Sheet1").Range("C2") = Sheets("Sheet1").Range("C2") - 1 Else (do not execute the macro and display message box = "stock at zero"

Thank you very much for your help.

1 answer

  1. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
     
    Hello,

     If Sheets("Feuil2").Range("C65536").End(xlUp) = "engine" And Sheets("Feuil1").Range("C2") > 0 Then
    Sheets("Feuil1").Range("C2") = Sheets("Feuil1").Range("C2") - 1
    Else
    '(do not execute the macro and show msgbox= "stock at zero"
    MsgBox "Stock at zero"
    'exit macro
    Exit Sub
    End If
    0