Remove a specific row when the value in a certain column is 0

zack8576

Active Member
Joined
Dec 27, 2021
Messages
271
Office Version
  1. 365
Platform
  1. Windows
I have this code that add up all the "CHAIN & EYEBOLT" in a entire excel file, count the quantity, and add a row to the end of the excel file with the quantity.
This code is used on thousands of excel files.

Sometimes some of these files contain 0 eyebolt & chain, for these, I do not want an additional row to be added. I am thinking there are 2 options:
1. modify this code so when the count is 0, no row is added.
2. modify this code so a row is added even if the qty is 0, but when it is 0, this row gets removed

Below is what I have so far, any pointers would be greatly appreciated !

VBA Code:
Public c As Range
Public lr As Long, lr2 As Long
Sub EyeboltsAndChains()
     lr2 = lr + 1                    
    Set c = ws1.Range("C" & lr2)  
    With c
        .Offset(, -2).Value = .Offset(-1, -2).Value
        .FormulaR1C1 = "=COUNTIF(R2C11:R" & lr & "C11,""CHAIN & EYEBOLT"")"
        .Value = .Value
        .Offset(, -1).Value = "!"
        .Offset(, 1).Value = "F09720"
        .Offset(, 6).Value = "Purchased"
        .Offset(, 8).Value = "CHAIN & EYEBOLT"
        .EntireRow.Font.Bold = True
    End With
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I was able to update the code and remove the new row, when the sum of the eyebolt and chain is 0
The code is working fine, but is this the best approach? Are there other better ways to accomplish this goal?

VBA Code:
Public c As Range
Public lr As Long, lr2 As Long
Sub EyeboltsAndChains()
    lr2 = lr + 1                    
    Set c = ws1.Range("C" & lr2)   
    With c
        .Offset(, -2).Value = .Offset(-1, -2).Value
        .FormulaR1C1 = "=COUNTIF(R2C11:R" & lr & "C11,""CHAIN & EYEBOLT"")"
        .Value = .Value
        .Offset(, -1).Value = "!"
        .Offset(, 1).Value = "F09720"
        .Offset(, 6).Value = "Purchased"
        .Offset(, 8).Value = "CHAIN & EYEBOLT"
        .EntireRow.Font.Bold = True
    End With
    If ws1.Range("C" & i3).Value Like "*0*" Then
            ws1.Rows(lr2).Delete
        End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
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