Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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: Code: -------------------- 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: Code: -------------------- 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 -- theDude ------------------------------------------------------------------------ theDude's Profile: http://www.excelforum.com/member.php...o&userid=16550 View this thread: http://www.excelforum.com/showthread...hreadid=375455 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I get old rows to auto delete when new are added? | Excel Discussion (Misc queries) | |||
How do you format an auto update to delete rows with expired date | Excel Worksheet Functions | |||
If formula result is false, how do I auto-delete that rows? | Excel Worksheet Functions | |||
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below | Excel Programming | |||
Auto Delete rows | Excel Programming |