Hi Danny,
Here are two versions that will do what you need...
This version prompts the user to enter the number of sets to delete:
Sub delete4Rows1()
Dim userCount As String, setCount, x, y As Integer
' Code point to jump back to if user makes data entry error...
Start:
' Prompt user to enter number of sets to delete...
userCount = InputBox("Enter number of sets to delete: ")
' Validate user entry to ensure it's a number (if not, alert user & start over)...
If Not IsNumeric(userCount) Then
' Alert user of data entry error...
MsgBox "ERROR: you must enter a number."
GoTo Start
End If
' If user didn't cancel the data entry dialog, start delete process...
If userCount <> "" Then
' Convert user entry to integer for loop routine limiter...
setCount = CInt(userCount)
' Select first row to delete...
ActiveSheet.Range("A2").Select
' Run set delete routine based on user entry...
For x = 1 To setCount
' Run row delete routine 4 times...
For y = 1 To 4
ActiveCell.EntireRow.Delete
Next y
' Skip over row not to delete...
ActiveCell.Offset(1, 0).Select
' Loop again based on user-entered set count...
Next x
End If
End Sub
This version doesn't prompt the user; it determines the number based on the range of data in the spreadsheet:
Sub delete4Rows2()
Dim x As Integer
' Start at first cell to evaluate...
ActiveSheet.Range("A1").Select
' Loop through every cell in used range...
For x = 1 To ActiveSheet.UsedRange.Rows.Count
' If empty or space in cell, delete row...
If ActiveCell.Value = "" Or ActiveCell.Value = " " Then
ActiveCell.EntireRow.Delete
Else
' Otherwise, a value exists in cell so skip row...
ActiveCell.Offset(1, 0).Select
End If
' Move to next cell in sheet and repeat...
Next x
End Sub
Hope this helps,
theDude
Bookmarks