Adding # of Blank Rows above Non-Blank Rows VBA help

BraytonM

New Member
Joined
Jul 25, 2021
Messages
24
Office Version
  1. 365
Hello all,

I need some help with my VBA. First, my VBA deletes any row where value in Column C is 0. That part works wonderful.

However, it is not properly adding the # of blank lines according to Column C. For instance, it does not add two lines above Row 2 and Row. It seems that the VBA will work for any value in Column C other than 2. I have added the minisheet here as well as the VBA that I am using.

Hopefully, y'all can help!

VBA Code:
Sub DeleteAndAdd()
Dim r As Long
Dim lastrow As Long
lastrow = Cells(Rows.Count, "C").End(xlUp).Row
For r = lastrow To 1 Step -1
If Cells(r, "C") = 0 Then
Rows(r).Delete
End If
Next r

lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row

For i = lastrow To 2 Step by - 1

    a = ActiveSheet.Cells(i, 3).Value
        For j = 1 To a
       
            ActiveSheet.Rows(i).Select
            Selection.Insert Shift:=xlDown
           
        Next

Next

ActiveSheet.Cells(1, 1).Select
End Sub
Cell Formulas
RangeFormula
A2:A29A2=RowTimesheet!T40
B2,B6B2=IF(A2<>"","ST","")
C2:C29C2=SUMPRODUCT((W2:AV2<>"")/COUNTIF(W2:AV2,W2:AV2&""))
B3B3=IF($A$3<>"","RH","")
B4B4=IF($A$4<>"","DT","")
B5B5=IF($A$5<>"","IW","")
B7B7=IF($A$7<>"","RH","")
B8B8=IF(A8<>"","DT","")
B9B9=IF($A$9<>"","IW","")
B10B10=IF($A$10<>"","ST","")
B11B11=IF($A$11<>"","RH","")
B12B12=IF($A$12<>"","DT","")
B13B13=IF($A$13<>"","IW","")
B14B14=IF($A$14<>"","ST","")
B15B15=IF($A$15<>"","RH","")
B16B16=IF(A$16<>"","DT","")
B17B17=IF($A$17<>"","IW","")
B18B18=IF($A$18<>"","ST","")
B19B19=IF($A$19<>"","RH","")
B20B20=IF($A$20<>"","DT","")
B21B21=IF($A$21<>"","IW","")
B22B22=IF($A$22<>"","ST","")
B23B23=IF($A$23<>"","RH","")
B24B24=IF($A$24<>"","DT","")
B25B25=IF($A$25<>"","IW","")
B26B26=IF($A$26<>"","ST","")
B27B27=IF($A$27<>"","RH","")
B28B28=IF($A$28<>"","DT","")
B29B29=IF($A$29<>"","IW","")
 
Last edited by a moderator:

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

Forum statistics

Threads
1,224,828
Messages
6,181,210
Members
453,023
Latest member
alabaz

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