Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Random Number of Rows 1

Status
Not open for further replies.

TommyP

MIS
Apr 16, 2001
30
US
Hi all, I am using Excel 97 and have a need to delete random rows. Let me explain...

I would like to present the user with an input box so they can select the number of rows to delete. Then delete those rows, skip one row, delete that same number of rows and skip a row, etc...

I cannot get this to work with macros. It always goes back to the top.

Can this be done???

tia
Tom Potter
 
Try the following macro and see if that's what you were looking for.

Public Sub DelSomRows()

Dim R As Long

Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If

rws = InputBox("Enter the number of rows to delete")

For R = 1 To Rng.Rows.Count

Rem Range("A" & R + 1).Select
For j = 1 To rws
Rng.Rows(R + 1).EntireRow.Delete

Next j

Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub

Indu I don't care about apathy.
 
Indu,

Thank you very much! That piece of code was EXACTLY what I was trying to accomplish!!!

Tom Potter
 
Tom - if Indu helped you out (which it certainly looks like), you should award a star. It's the only recognition that people get for their efforts and it is also very useful for those who browse the archives as it gives an indicator that a good / useful answer to the question was given. To award a star, just click on the "Mark this post as a helpful/expert post" link at the bottom of the post which was helpful[thumbsup][yinyang]

Rgds
~Geoff~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top