New to VBA: Go to Next If Statement

mrfy6

New Member
Joined
Jul 9, 2019
Messages
2
I have some code that I am messing with for a pet project at work for an inventory form. I have the pictures of an item with macros for a mouse click to remove one from the "on hand" inventory. in Sheet 1.

From there, I have on Sheet 2 the "inventory database" which includes the Quantity on hand(which references the on hand qty in Sheet 1), the "trigger Qty" for the email to be sent, and the Target Qty. for reordering purposes and this is shown in my email.

Where I am having trouble is: The program will run the FIRST line, but then when I adjust the Inventory for any other line item, it will NOT call mail for that line. As you can see I've tried to move all of my "Exit Sub" to the end of the data to attempt to let the macro run all of the above before exiting.

Can someone please help?

Thank you!

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'SAJ
    
    If Worksheets("TAG_INV").Range("F2") < 0 Then
            Call Mail_SAJ
'SB2


    If Worksheets("TAG_INV").Range("F3") < 0 Then
            Call Mail_SB2
'S43_SAN
    
    If Worksheets("TAG_INV").Range("F9") < 0 Then
            Call Mail_S43_SAN
'S00_S17
    
    If Worksheets("TAG_INV").Range("F8") < 0 Then
            Call Mail_S00_S17
'SAH_SCE
    
    If Worksheets("TAG_INV").Range("F4") < 0 Then
            Call Mail_SAH_SCE
'SAF_SCU
    
    If Worksheets("TAG_INV").Range("F6") < 0 Then
            Call Mail_SAF_SCU
'SB5_SCN
    
    If Worksheets("TAG_INV").Range("F7") < 0 Then
            Call Mail_SB5_SCN
'SB9_SCF
    
    If Worksheets("TAG_INV").Range("F5") < 0 Then
            Call Mail_SB9_SCF
'SC8
    
    If Worksheets("TAG_INV").Range("F11") < 0 Then
            Call Mail_SC8
'SBK
    
    If Worksheets("TAG_INV").Range("F10") < 0 Then
            Call Mail_SBK
'SB2
    
    If Worksheets("TAG_INV").Range("F3    ") < 0 Then
            Call Mail_SB2
    
    If Worksheets("TAG_INV").Range("D2") > Worksheets("TAG_INV").Range("C2") Then Exit Sub
    If Worksheets("TAG_INV").Range("D3") > Worksheets("TAG_INV").Range("C3") Then Exit Sub
    If Worksheets("TAG_INV").Range("D9") > Worksheets("TAG_INV").Range("C9") Then Exit Sub
    If Worksheets("TAG_INV").Range("D8") > Worksheets("TAG_INV").Range("C8") Then Exit Sub
    If Worksheets("TAG_INV").Range("D4") > Worksheets("TAG_INV").Range("C4") Then Exit Sub
    If Worksheets("TAG_INV").Range("D6") > Worksheets("TAG_INV").Range("C6") Then Exit Sub
    If Worksheets("TAG_INV").Range("D7") > Worksheets("TAG_INV").Range("C7") Then Exit Sub
    If Worksheets("TAG_INV").Range("D5") > Worksheets("TAG_INV").Range("C5") Then Exit Sub
    If Worksheets("TAG_INV").Range("D11") > Worksheets("TAG_INV").Range("C11") Then Exit Sub
    If Worksheets("TAG_INV").Range("D10") > Worksheets("TAG_INV").Range("C10") Then Exit Sub
    If Worksheets("TAG_INV").Range("D3") > Worksheets("TAG_INV").Range("C3") Then Exit Sub
    
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
     
    
    End If
    
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
How about

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Worksheets("TAG_INV").Range("F2") < 0 Then Call Mail_SAJ
    If Worksheets("TAG_INV").Range("F3") < 0 Then Call Mail_SB2
    If Worksheets("TAG_INV").Range("F9") < 0 Then Call Mail_S43_SAN
    If Worksheets("TAG_INV").Range("F8") < 0 Then Call Mail_S00_S17
    If Worksheets("TAG_INV").Range("F4") < 0 Then Call Mail_SAH_SCE
    If Worksheets("TAG_INV").Range("F6") < 0 Then Call Mail_SAF_SCU
    If Worksheets("TAG_INV").Range("F7") < 0 Then Call Mail_SB5_SCN
    If Worksheets("TAG_INV").Range("F5") < 0 Then Call Mail_SB9_SCF
    If Worksheets("TAG_INV").Range("F11") < 0 Then Call Mail_SC8
    If Worksheets("TAG_INV").Range("F10") < 0 Then Call Mail_SBK
    
'[COLOR=#ff0000]I do not understand this part of your code, since it does not do anything.[/COLOR]
    If Worksheets("TAG_INV").Range("D2") > Worksheets("TAG_INV").Range("C2") Then Exit Sub
    If Worksheets("TAG_INV").Range("D3") > Worksheets("TAG_INV").Range("C3") Then Exit Sub
    If Worksheets("TAG_INV").Range("D9") > Worksheets("TAG_INV").Range("C9") Then Exit Sub
    If Worksheets("TAG_INV").Range("D8") > Worksheets("TAG_INV").Range("C8") Then Exit Sub
    If Worksheets("TAG_INV").Range("D4") > Worksheets("TAG_INV").Range("C4") Then Exit Sub
    If Worksheets("TAG_INV").Range("D6") > Worksheets("TAG_INV").Range("C6") Then Exit Sub
    If Worksheets("TAG_INV").Range("D7") > Worksheets("TAG_INV").Range("C7") Then Exit Sub
    If Worksheets("TAG_INV").Range("D5") > Worksheets("TAG_INV").Range("C5") Then Exit Sub
    If Worksheets("TAG_INV").Range("D11") > Worksheets("TAG_INV").Range("C11") Then Exit Sub
    If Worksheets("TAG_INV").Range("D10") > Worksheets("TAG_INV").Range("C10") Then Exit Sub
    If Worksheets("TAG_INV").Range("D3") > Worksheets("TAG_INV").Range("C3") Then Exit Sub
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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