VBA code to zero out gross margin if it is forecast sales order

ageboo43

New Member
Joined
Aug 16, 2016
Messages
2
If column E (customer Name) contains the word "Forecast", then zero out value in column M (gross margin).
Data range will varies every day, row 4 is header, data value will be from row 5 to around row 3000. (size changes every day, but 3000 rows will probably cover them all).
Please help. And thank you in advance.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Welcome to the Board!

Try this procedure:
VBA Code:
Sub MyClearMacro()

    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row with data in column E
    lr = Cells(Rows.Count, "E").End(xlUp).Row
    
'   Loop through all rows starting in row 5
    For r = 5 To lr
'       Check column E for the word "Forecast"
        If InStr(1, UCase(Cells(r, "E")), "FORECAST") > 0 Then
'           Zero out column M
            Cells(r, "M") = 0
        End If
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
Welcome to the Board!

Try this procedure:
VBA Code:
Sub MyClearMacro()

    Dim lr As Long
    Dim r As Long
   
    Application.ScreenUpdating = False
   
'   Find last row with data in column E
    lr = Cells(Rows.Count, "E").End(xlUp).Row
   
'   Loop through all rows starting in row 5
    For r = 5 To lr
'       Check column E for the word "Forecast"
        If InStr(1, UCase(Cells(r, "E")), "FORECAST") > 0 Then
'           Zero out column M
            Cells(r, "M") = 0
        End If
    Next r
   
    Application.ScreenUpdating = True
   
End Sub
It works perfectly. Thank you very much.
 
Upvote 0
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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