VBA Insert Rows

Littlemalky

Board Regular
Joined
Jan 14, 2011
Messages
223
I have data in columns "A:V", with a varying range of data in these columns each week, but the columns and their headers are static. I have a complicated sort and breaks that I use in order to create pivot tables. Anyway, the situation is that I sort column "S" in ascending order and create a break by inserting 4 empty rows when the first 4 appears in that column. Now I have two portions of data, the upper and lower. Now I resort just the upper portion of data by column "V" in descending order. This column is composed of percentages. I need to create another break, preferably inserting 4 rows, for everything less than 100% in column "V" so that only the top portion has 100%+ percentages in it.

My previous code for inserting rows when it finds a 4 is this, so I'm wondering if anyone knows how to adjust it so that it will just use the top portion of data for the percentages part:
Code:
Private Sub Insert_Rows() 'Inserts break between 3 & 4 days late
    Dim Found As Range
    Dim counter As Long, sMax As Long
    
    sMax = Application.Max(Range("S:S"))
    counter = 4
    
    Do
    
        Set Found = Range("S:S").Find(counter, Range("S1"), xlValues, xlWhole, xlByRows, xlNext)
        If Not Found Is Nothing Then Found.Resize(4).EntireRow.Insert
        counter = counter + 1
        
    Loop Until Not Found Is Nothing Or counter > sMax
    
    'If Found Is Nothing Then MsgBox "Can't find four or larger."
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
some pointers:
intersect(range("V1").currentregion,range("V:V"))
should be the range you want to search, but since you're looking for the first value <100% rather than an exact value you could consider a loop to run down the cells of that range to search, or use Application.worksheetfunction.Match to get the index of the first value below 100%. Match follows the same rules in vba as the sheet function.
Note that you might have to use <1 rather than <100% but I'm not sure.
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

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