ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   delete every X row, insert everyY row (https://www.excelbanter.com/excel-discussion-misc-queries/144395-delete-every-x-row-insert-everyy-row.html)

[email protected]

delete every X row, insert everyY row
 
Hi,

Just wondering is there a formula/code to delete every X th row in a
high-lighted range?

or to insert a row every Y row?

Thanks :)

elaine.


Bob Phillips

delete every X row, insert everyY row
 
You could add a formula in an empty column

=MOD(ROW(),2)=0

and then filter that column by a value of TRUE and delete the visible rows.

, 2 gives the even rows. Change the ,2 to get other rows as the deletion
rows.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

wrote in message
ups.com...
Hi,

Just wondering is there a formula/code to delete every X th row in a
high-lighted range?

or to insert a row every Y row?

Thanks :)

elaine.




PlayingToAudienceOfOne

delete every X row, insert everyY row
 
Public Sub DeleteEveryNthRowQuickly(Optional N As Long = 2)
'The default is to delete every 2nd row
Application.ScreenUpdating = False
On Error Resume Next
With ActiveSheet.UsedRange
With .Columns(.Columns.Count).Offset(, 1).Cells
.Item(N) = True
Range(.Item(1), .Item(N)).AutoFill .Cells
.SpecialCells(xlConstants).EntireRow.Delete
End With
End With
Application.ScreenUpdating = True
End Sub


P.S. Awaiting Mr. Phillips' public ridicule.

" wrote:

Hi,

Just wondering is there a formula/code to delete every X th row in a
high-lighted range?

or to insert a row every Y row?

Thanks :)

elaine.




All times are GMT +1. The time now is 08:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com