#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro

I have a macro question for excel...I am a novice when it comes to visual
basic functions because I don't program really at all. I run certain reports
every month that are in text format. For everyones wellbeing I import them
into excel and perform certain formatting functions. There is on report that
is quite big. What I have found is that every 35 rows there are 20 rows that
I delete in the report. I want a macro that will count 35 rows then delete
20 rows and then count another 35 rows and delete 20 until it reaches the end
of the selection. Any Ideas or suggestion would be appreciated. I am using
Microsoft Excel 2000 SP3.


Thanks Matthew Pietz

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Macro

Matt

You could try something like this. Save your data before testing:

Sub DelRows()

Dim totRows As Long
Dim reps As Double
Dim counter As Integer

Range("A4").Select 'Assumes data starts in A4
totRows = Selection.CurrentRegion.Rows.Count
reps = Round(totRows / 55, 0)
For counter = 1 To reps
ActiveCell.Offset(35, 0).Select
ActiveCell.Offset(0, 0).Range("A1:A20").EntireRow.Delete
Next counter

End Sub


Regards
Rowan


"Matt Pietz" wrote:

I have a macro question for excel...I am a novice when it comes to visual
basic functions because I don't program really at all. I run certain reports
every month that are in text format. For everyones wellbeing I import them
into excel and perform certain formatting functions. There is on report that
is quite big. What I have found is that every 35 rows there are 20 rows that
I delete in the report. I want a macro that will count 35 rows then delete
20 rows and then count another 35 rows and delete 20 until it reaches the end
of the selection. Any Ideas or suggestion would be appreciated. I am using
Microsoft Excel 2000 SP3.


Thanks Matthew Pietz

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Macro

Hello Matt,

Assuming Column A is a good column to test in terms of the last data cell,
open your immediate window in your VBE (Ctrl-G), and see if the following
procedure returns the ranges you'd like to delete:

Sub tester()
Dim y As Variant, z As Long
y = Evaluate("transpose(OFFSET(a1,(row(1:" & _
Range("a65536").End(xlUp).Row \ 35 & "))*35-1,0,21,1))")
For z = LBound(y) To UBound(y)
Debug.Print y(z).Address
Next
End Sub

If it does, you can use the array of range objects to delete your desired
ranges by iterating backwards through the array as such:

Sub delTime()
Dim y As Variant, z As Long
y = Evaluate("transpose(OFFSET(a1,(row(1:" & _
Range("a65536").End(xlUp).Row \ 35 & "))*35-1,0,20,1))")
Application.ScreenUpdating = False
For z = UBound(y) To LBound(y) Step -1
y(z).EntireRow.Delete
Next
Application.ScreenUpdating = True
End Sub

Regards,
Nate Oliver
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 recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
how to count/sum by function/macro to get the number of record to do copy/paste in macro tango Excel Programming 1 October 15th 04 01:16 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 05:14 PM.

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"