Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default Delete every other two row MACRO

Hello:

I need a macro to delete every other rows starting from row2. For example
Col B
Row2: Test1-a
Row3 Test1-b
Row4 Test1-c
Row5: Test2-a
Row6: Test2-b
Row7: Test2-c

In other words, I'd like the macro to delete row 3-4 (b-c) and 6-7 (b-c),
and so on

Thanks again,
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,805
Default Delete every other two row MACRO

Try the macro below.
Replace 99 with the last row you want to leave (has to be multiple of 3)

Sub DelRow()
Application.ScreenUpdating = False
For i = 99 To 3 Step -3
Range("A" & i & ":A" & i + 1).Select
Selection.EntireRow.Delete
Next i
Application.ScreenUpdating = True
End Sub

"bioyyy" wrote:

Hello:

I need a macro to delete every other rows starting from row2. For example
Col B
Row2: Test1-a
Row3 Test1-b
Row4 Test1-c
Row5: Test2-a
Row6: Test2-b
Row7: Test2-c

In other words, I'd like the macro to delete row 3-4 (b-c) and 6-7 (b-c),
and so on

Thanks again,

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,344
Default Delete every other two row MACRO

Hi,

The following code deletes a row at every 6th line. To use it for any other
number of lines simply change the 6 in the first row of code to the number
you want.

To use it select a vacant range of cells in a single column corresponding to
the height of the range you want to delete rows from and run the macro.
Tools Macro Macros.

I adjusted the code for your sample.

Sub InsertRows()
Selection = "=1/MOD(ROW(),2)"
Selection = Selection.Value
Selection.SpecialCells(xlCellTypeConstants, 16).EntireRow.Delete
Selection.EntireColumn.Delete
End Sub

This code runs extremely fast.

To add this code to a workbook:
1. Press Alt+F11 (opens the Visual Basic Editor)
2. Select your file in the Project - VBA Project window, top left (press
Ctrl+R if you do not see it.)
3. Choose Insert Module
4. Copy the code above to the module on the right

If this helps, please click the Yes button.
--
Thanks,
Shane Devenshire


"bioyyy" wrote:

Hello:

I need a macro to delete every other rows starting from row2. For example
Col B
Row2: Test1-a
Row3 Test1-b
Row4 Test1-c
Row5: Test2-a
Row6: Test2-b
Row7: Test2-c

In other words, I'd like the macro to delete row 3-4 (b-c) and 6-7 (b-c),
and so on

Thanks again,

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default Delete every other two row MACRO

Sheeloo. Thanks for a big help again.



"Sheeloo" wrote:

Try the macro below.
Replace 99 with the last row you want to leave (has to be multiple of 3)

Sub DelRow()
Application.ScreenUpdating = False
For i = 99 To 3 Step -3
Range("A" & i & ":A" & i + 1).Select
Selection.EntireRow.Delete
Next i
Application.ScreenUpdating = True
End Sub

"bioyyy" wrote:

Hello:

I need a macro to delete every other rows starting from row2. For example
Col B
Row2: Test1-a
Row3 Test1-b
Row4 Test1-c
Row5: Test2-a
Row6: Test2-b
Row7: Test2-c

In other words, I'd like the macro to delete row 3-4 (b-c) and 6-7 (b-c),
and so on

Thanks again,

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to delete row Woodi2 Excel Worksheet Functions 13 November 20th 07 03:29 AM
delete a macro that isn't in macro list Jane Makinson Excel Discussion (Misc queries) 3 March 13th 06 01:10 PM
How can I delete a macro when the Delete button is not active? FCR Excel Worksheet Functions 0 March 9th 06 09:43 AM
How do i delete a macro in Excel 2003 when delete isn't highlight Abel Excel Discussion (Misc queries) 2 September 13th 05 04:09 AM
Macro to delete a row kiran Excel Discussion (Misc queries) 1 September 1st 05 06:45 AM


All times are GMT +1. The time now is 09:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"