Insert Row if the Entire Row Cell has Zero

unknownymous

Board Regular
Joined
Sep 19, 2017
Messages
249
Office Version
  1. 2016
Platform
  1. Windows
Hi Guys,

How can I insert a blank row if the entire row has zero ?

Before:

NameTrack1Track2Track3Track4
Ben1112
Sam3456
Anna1059
Ted0000

<tbody>
</tbody>


After:

NameTrack1Track2Track3Track4
Sam3456
Ben1112
Anna1059
ZEROES
Ted0000

<tbody>
</tbody>


Thanks in advance for the help.
 
Hi Peter,

See more detailed illustration...

Before:

IDNameBlankBlankScore1Score2BlankBlankScore3 -14Note1-12
1Ann821OK
2Sef010-
3Ben000OK
4Lei001-

<tbody>
</tbody>

After:

IDNameBlankBlankScore1Score2BlankBlankScore 3-14Note1-11
1Ann821OK
2Sef010Check
4Lei001Check
3Ben000OK

<tbody>
</tbody>

Whereas:

*Score 3-14 range from I4:T4
*Note 1-11 range from U4:AE4

Separate Ben as his score is "Zero" from Score 1 to 14

Thanks a lot in advance! :)
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
If the columns to check are C:T (excluding those blank in the header row) then try
Code:
Sub insertRows_v3()
  Dim a As Variant, aRws As Variant, aCols As Variant
  Dim i As Long
  Dim sTest As String
  
  Const hr As Long = 4   '<- Header row
 
  Application.ScreenUpdating = False
  aRws = Evaluate("row(" & hr + 1 & ":" & Range("A" & Rows.Count).End(xlUp).Row & ")")
  aCols = Filter(Evaluate(Replace("if(len(#),column(#),""x"")", "#", "C" & hr & ":T" & hr)), "x", False)
  a = Application.Index(Cells, aRws, aCols)
  sTest = Mid(Replace(String(UBound(a, 2), "0"), 0, "|0"), 2)
  For i = UBound(a) To 2 Step -1
    If Join(Application.Index(a, i, 0), "|") = sTest Then Rows(i + hr).Insert
  Next i
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
You're welcome.

Hi Guys,

What if i want to insert a row if both Score 1 & 2 is zero? How can I do that?

NameCityStateCountryScore1Score2
BenBostonMAUS42
SeanLondonN/AUK32
EmsParisN/AFR00

<tbody>
</tbody>


Thanks in advance!
 
Upvote 0
1. What columns are we looking at?
2. Are there other columns on the sheet with data besides the ones shown?
3. Is the order of columns likely to change? That is, will Score1 and Score2 always be in the same columns?
4. Are we adding a row above or below the row with two zeroes?
 
Upvote 0
Robert, a comment on your code. It may not be possible with the OP's data but it would insert a blank row above a row that contained
3, 4, -1, -6

It would also insert a blank row above a row that was already blank in those 4 columns.

In both examples above the rows don't meet the OP's stated requirement.

Mr. Peter SSs
Pardon my incursion, but may I know the meaning of OP ?
many thanks
 
Upvote 0
Hi Peter,

See below:

1. As for my example above, Ems should be separated so additional row will set as separator - that is if the Score1 & 2 is ZERO
2. No additional columns
3. The order of the column will remain the same
4. We're adding a row above the row with two zeroes.

Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,043
Members
449,092
Latest member
ikke

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