Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Need help to auto delete 4 of every 5 rows

I have a spreadsheet in which 4 of every 5 Rows need to be deleted. ie: Row
1 is good, Row 6 is good, Row 11 is good, Row 16 is good, etc. I need to
delete Rows 2-5, 7-10, 12-15, etc. I would prefer to set a variable in the
macro to tell it how many sets of 4 consecutive rows I need deleted (with one
good row between each bad set of 4). The rows that need to be deleted are not
entirely blank, some of the cells have data (not needed) but there are a few
rows that are entirely blank. It needs to delete the rows irreguardless of
any data in that row. Help is appreciated as I am not a programmer but you
guys are really good.

OR

Every 5th cell in column A has data. I need to delete all ROWS that have no
data in COLUMN A(even if it is a "space" that was used to delete previous
data) in column A. How would it know when it reached the end of the data and
continue to delete the balance of the blank spreadsheet?

Thanks
Danny


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need help to auto delete 4 of every 5 rows


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

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
How do I get old rows to auto delete when new are added? Skippy Lou Excel Discussion (Misc queries) 1 May 7th 09 11:31 PM
How do you format an auto update to delete rows with expired date Rneedshelp Excel Worksheet Functions 0 May 29th 07 04:30 PM
If formula result is false, how do I auto-delete that rows? jbrenner51 Excel Worksheet Functions 1 November 16th 05 05:24 PM
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 Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM
Auto Delete rows anurag.d[_9_] Excel Programming 5 July 2nd 04 12:11 PM


All times are GMT +1. The time now is 03:40 AM.

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

About Us

"It's about Microsoft Excel"