Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
With the code posted below, I am trying to add 'mrow' number of blank ranges to my worksheet.
pda_cnt = 20 (a count of rows in a particular area of my worksheet). There has to be a minimum of 24 rows in this area. So, since 20 is less than 24 (pda_cnt < 24), we need to add enough rows to bring that area up to 24.
'mrow' represents the number of rows that need to be added to bring this area up to the minimum 24 rows. In this case, mrow = 4
The L2 loop adds these empty ranges (A:Q) at row rng_pda_end which = 33.
I expect the loop to end after 4 loops, but it keeps going beyond.
Thoughts?
Code:
rng_pda_end = Application.WorksheetFunction.Match("Facility Maintenance Activities", .Columns(1)) - 3
pda_cnt = rng_pda_end - 13
If pda_cnt < 24 Then
mrow = 24 - pda_cnt
For L2 = 1 To mrow
.Range("A" & rng_pda_end & ":Q" & rng_pda_end).Insert Shift:=xlDown
Next L2
End If
pda_cnt = 20 (a count of rows in a particular area of my worksheet). There has to be a minimum of 24 rows in this area. So, since 20 is less than 24 (pda_cnt < 24), we need to add enough rows to bring that area up to 24.
'mrow' represents the number of rows that need to be added to bring this area up to the minimum 24 rows. In this case, mrow = 4
The L2 loop adds these empty ranges (A:Q) at row rng_pda_end which = 33.
I expect the loop to end after 4 loops, but it keeps going beyond.
Thoughts?