![]() |
need macro script - repeat to delete 2 rows
I need to repeat deleting 2 rows, skipping 1 row, then deleting 2 rows again
and skipping 1 row. How to run macro on this? Please help. |
need macro script - repeat to delete 2 rows
Try:
Sub delete_rows() Dim r As Range, j As Long Set r = ActiveSheet.UsedRange j = r.Rows.Count + r.Row Set rdel = Cells(j, "A") k = 0 For i = 1 To j - 1 k = k + 1 If k = 4 Then k = 1 End If If k = 3 Then Else Set rdel = Union(rdel, Cells(i, "A")) End If Next rdel.EntireRow.Delete End Sub -- Gary's Student "BB" wrote: I need to repeat deleting 2 rows, skipping 1 row, then deleting 2 rows again and skipping 1 row. How to run macro on this? Please help. |
need macro script - repeat to delete 2 rows
Thank you. It works, however it delete the columns and keep each row of
column D. I need all info in the row. How do you figure it out this complicated script? Can you show me how to use record and stop record in macro easy steps? "Gary''s Student" wrote: Try: Sub delete_rows() Dim r As Range, j As Long Set r = ActiveSheet.UsedRange j = r.Rows.Count + r.Row Set rdel = Cells(j, "A") k = 0 For i = 1 To j - 1 k = k + 1 If k = 4 Then k = 1 End If If k = 3 Then Else Set rdel = Union(rdel, Cells(i, "A")) End If Next rdel.EntireRow.Delete End Sub -- Gary's Student "BB" wrote: I need to repeat deleting 2 rows, skipping 1 row, then deleting 2 rows again and skipping 1 row. How to run macro on this? Please help. |
need macro script - repeat to delete 2 rows
Using the recorder to automate what you do manually is a very good start.
The recorder is not good for teaching about loops or conditional statements. It goes not help to learn about ranges either. Get the VBA for dummies book checkout: http://www.functionx.com/vbaexcel/index.htm -- Gary's Student "BB" wrote: Thank you. It works, however it delete the columns and keep each row of column D. I need all info in the row. How do you figure it out this complicated script? Can you show me how to use record and stop record in macro easy steps? "Gary''s Student" wrote: Try: Sub delete_rows() Dim r As Range, j As Long Set r = ActiveSheet.UsedRange j = r.Rows.Count + r.Row Set rdel = Cells(j, "A") k = 0 For i = 1 To j - 1 k = k + 1 If k = 4 Then k = 1 End If If k = 3 Then Else Set rdel = Union(rdel, Cells(i, "A")) End If Next rdel.EntireRow.Delete End Sub -- Gary's Student "BB" wrote: I need to repeat deleting 2 rows, skipping 1 row, then deleting 2 rows again and skipping 1 row. How to run macro on this? Please help. |
All times are GMT +1. The time now is 09:48 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com