deleting rows automatically using a maco or vba

I have a report that comes to me in Excel 2003.  I need to remove the first 3 
and last 3 rows.  The report in between may vary on the number of rows 
however.  It is basically a repetion I want to forgo.
0
Utf
2/1/2010 1:42:01 PM
excel.programming 6508 articles. 2 followers. Follow

4 Replies
1805 Views

Similar Articles

[PageSpeed] 22

This assumes that col A is filled on the last row:

Sub RowRemover()
Dim n As Long
Dim s As String
n = Cells(Rows.Count, "A").End(xlUp).Row
s = n - 2 & ":" & n
Rows(s).Delete
Rows("1:3").Delete
End Sub
-- 
Gary''s Student - gsnu201001


"outrigger" wrote:

> I have a report that comes to me in Excel 2003.  I need to remove the first 3 
> and last 3 rows.  The report in between may vary on the number of rows 
> however.  It is basically a repetion I want to forgo.
0
Utf
2/1/2010 2:01:01 PM
Sub removetopandbottomthreerows()
dim lr as long
lr = Cells(Rows.Count, 1).End(xlUp).Row
Rows(lr - 2).Resize(3).Delete
Rows(1).Resize(3).Delete
End Sub


Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett@gmail.com
"outrigger" <outrigger@discussions.microsoft.com> wrote in message 
news:A150C020-405C-4B6A-B386-827ACEFEEE49@microsoft.com...
>I have a report that comes to me in Excel 2003.  I need to remove the first 
>3
> and last 3 rows.  The report in between may vary on the number of rows
> however.  It is basically a repetion I want to forgo. 

0
Don
2/1/2010 2:08:27 PM
I use this to remove blank rows.

Hydra

' This function removes all blank rows from the working area of the 
Spreadsheet.
Sub EraseBlankRows()
    Dim rng As Range, nrows As Long, ncols As Long

    With ActiveSheet
        Set rng = .Cells.SpecialCells(xlLastCell)
        nrows = rng.Row
        ncols = rng.Column
        Nrow = 1
        For Nrow = nrows To 1 Step -1
            Set rng = .Cells(Nrow, 1).EntireRow
            If BlankCellCount(rng) = ncols Then rng.Delete xlShiftUp
        Next Nrow
    End With
End Sub


Private Function BlankCellCount(ByVal rng As Range) As Long
    On Error Resume Next
    BlankCellCount = rng.SpecialCells(xlCellTypeBlanks).Count
End Function




"Gary''s Student" wrote:

> This assumes that col A is filled on the last row:
> 
> Sub RowRemover()
> Dim n As Long
> Dim s As String
> n = Cells(Rows.Count, "A").End(xlUp).Row
> s = n - 2 & ":" & n
> Rows(s).Delete
> Rows("1:3").Delete
> End Sub
> -- 
> Gary''s Student - gsnu201001
> 
> 
> "outrigger" wrote:
> 
> > I have a report that comes to me in Excel 2003.  I need to remove the first 3 
> > and last 3 rows.  The report in between may vary on the number of rows 
> > however.  It is basically a repetion I want to forgo.
0
Utf
2/1/2010 2:17:01 PM
Don,
Excellant, that was the best one.
Thanks Don!

"Don Guillett" wrote:

> Sub removetopandbottomthreerows()
> dim lr as long
> lr = Cells(Rows.Count, 1).End(xlUp).Row
> Rows(lr - 2).Resize(3).Delete
> Rows(1).Resize(3).Delete
> End Sub
> 
> 
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> dguillett@gmail.com
> "outrigger" <outrigger@discussions.microsoft.com> wrote in message 
> news:A150C020-405C-4B6A-B386-827ACEFEEE49@microsoft.com...
> >I have a report that comes to me in Excel 2003.  I need to remove the first 
> >3
> > and last 3 rows.  The report in between may vary on the number of rows
> > however.  It is basically a repetion I want to forgo. 
> 
> .
> 
0
Utf
3/19/2010 3:46:12 PM
Reply:

Similar Artilces:

Pivot Table row comparison
I'm trying to compare an old customer schedule with their new schedule and highlight the changes with colour or by hiding a row. My pivot table looks like this Prod Sched wk1 wk2 wk3 A old 3 2 3 A new 3 4 3 B old 2 2 2 B new 2 2 2 So in the above example I'd like to colour the cells for wk2- Product A in yellow, and hide the product B rows as there has been no change in demand. Can someone give me some advice about how to do this Thanks for your help Ross How about an alternative??? Your raw data looks kind of like this: Prod Sched wk# qty...

How to Recover Deleted Sent Mail?
While trying to delete very old "Sent" mail I seem to have deleted all "Sent" mail. Is there a way of recovering this mail? Have you closed Outlook since deleting the old sent mail? http://www.howto-outlook.com/howto/restoredeleteditemsfromanoutlookpst.htm might help. Next time, archive the items you want removed from your active .pst file. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. After furious head scratching, Sidney Friedman as...

Using Popups to select a range of cells.
Hi All I have a small request for help with code. I need a macro to have popups request the first and last cells in a range , and then to select them. Can someone help? Sub test() Dim Rng As Range On Error Resume Next Set Rng = Application.InputBox("Select your range", _ "Mousework", Type:=8) On Error GoTo 0 If Rng Is Nothing Then Exit Sub MsgBox Rng.Address End Sub HTH. Best wishes Harald "Colin Hayes" <Colin@chayes.demon.co.uk> wrote in message news:8mYkILA1YlvLFw7Z@chayes.demon.co.uk... > > Hi All > >...

Cannot delete subreport
I am using Access 2003 and have a report I did a while back with a simple subreport. I want to remove the subreport but for the life of me can't figure out how to do it. Any help would be greatly appreciated. Thanks. Hi - When you say "remove the sub report", what do you mean? Do you want to delete the entire subreport control containing the subreport, or do you want to keep the control, but change the report contained in it? The first is easy - select the control by clicking once on it once, then press delete. For the second, click the control once, then set ...

Unable to automatic close Outlook
After installing CRM Outlook client on laptop it isn't possible to close pc. This funtionality closes all open programs and shut down computer. After CRM is installed Outlook needs to be closed manual. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.micro...

Rule for Deleted Items
I am being told that there is a rule in place on my Exchange server that will not empty the deleted items folder every 30 days for certain users in my organization. I found a recipient policy in System Manager that says "Users Excluded from Mailbox Cleanup" but it only shows 2 users and not the 3 I was told about. But I have confirmed that the missing person has email in her deleted items folder going back to 2005 so it must be working. Is there any other location I should be looking? Also, we just had someone come in and migrate our Exchange environment from 2000 to a new...

I need to show the last number in a rows in the total pending row
I have a column where I list pending cases each month and I need to show the last number in the total pending cell at the bottom of the row. I can use an offset fomula which works if the pending cases begin in row 1. However, I am not able to get it to work if the pending cases begin in rows 4 or 5 as an example. Any suggestion? Rows don't have a bottom.............guess you meant Column. Last number in column A =LOOKUP(99^99,A:A) Last anything in column A =LOOKUP(2,1/(A1:A65535<>""),A1:A65535) Gord Dibben MS Excel MVP On Wed, 28 Jan 2009 16:30:08 -0800, Jen S ...

I can receive but cannot send messages using outlook 2003
Task 'POP3.com - Sending' reported error (0x8004210B) : 'The operation timed out waiting for a response from the sending (SMTP) server. If you continue to receive this message, contact your server administrator or Internet service provider (ISP).' "UJ" <UJ@discussions.microsoft.com> wrote in message news:88595AE2-844E-4B15-ACE4-C283F972DBB6@microsoft.com... > > Task 'POP3.com - Sending' reported error (0x8004210B) : 'The operation timed > out waiting for a response from the sending (SMTP) server. If you continue to > re...

number of rows #2
I used autoformat so that my rows would alternate colors. But, it added a bunch of empty rows so that the sheet is maxed out and my file is huge. I don't need all those empty rows and I can't find a way to delete them. Any suggestions for how to get rid of the rows, or limit the number of rows on a worksheet? I know I could copy all the data to a new worksheet, but I'd like a better solution. Try this: click on the number of the first empty row, so the whole row is selected. Using the vertical scrollbar, go to the last row on the sheet. Hold down the shift key while you cli...

cannot delete message from deleted items
I have a message in my deleted items folder that when choosing delete opens the McAfee box warning of potential virus and wants me to choose open or do not open, but will not delete. I have tried choosing another file and holding ctrl and choosing the file I want deleted and then choosing delete, I have tried moving it to the desktop but it will only copy there, I have tried every form of delete possible. I need help. Anyone know how? Outlook 2002. Can you empty the deleted items folder entirely? Or turn off the McAfee scanning temporarily to see if it makes a difference? Julie wr...

how can I export data by VBA and specify type of delimitor
I want to export data from excel by VBA and specify to use ',' as delimitor. but I can only export a file rename to .csv. but when I open it, it still a excel file, but not a text file. How can I do it? Million thanks. You could (temporarily???) change your windows list separator: Windows start button|Settings|control panel regional and language Settings Options applet. regional Options tab|customize button List separator near the bottom of the dialog. Or you could use a macro. You could borrow some code from one of these sites: Chip Pearson's: http://www.cpearson.com/excel/...

I can not delete a duplicate personal folders list #2
Vall... amazing that there isn't an easy fix for this. The instructions provided simply don't work ( tools-email accounts-view change email accounts-deliver to new account-finish-close outlook and reopen ), and none of the other offered explanations have worked either. As this is such a common problem; why hasn't microsoft provided a very EASY fix? I am more confused ( and frightened ) and don't want to make the problem worse! Your profile is corrupt, probably based on an incorrect migration of your ..pst file. Create a new mail profile and configure it to use your exi...

INF for Ports class CDC USB device using usbser.sys fails DTM INFT
If a USB-to-serial CDC ACM specification device using usbser.sys is not classified as a modem, the New Hardware Wizard will not install the Virtual COM Port unless the INF file AddService directive Flags parameter has a value of 2 to set the SPSVCINST_ASSOCSERVICE bit. This causes both ChkInf and the DTM "INFTest for a single .INF" to fail with error "(E.22.1302) Filter drivers cannot be the controlling service (SPSVCINST_ASSOCSERVICE)." To certifiy the driver for a device that otherwise passes WINQUAL testing but is less complicated than a modem, is there any...

Retrieval of Deleted Items After Being Deleted from the Deleted Items File
I deleted a number of important emails from the deleted items file in Outlook 2000. This may sound stupid, but I completely emptied the deleted items file instead of deleting them one by one. Pretty stupid, huh. Anyone. Can they be retrieved? Please help. Thanks. Sorry for sending this again but I seem to be computer illiterate and it has taken me some time to explain the whole situation. Thanks again. unless you use Exchange server with deleted retention enabled, you are most likely out of luck, but you can try something that might help.... http://www.outlook-tips.net/howto/r...

Using c# object in Excel VBA
Hi All I have writen an COM Object in C# to use it in Excel. This Object has a Function that delivers a List of Users from a Database. My problem is now that I get the List of Users but it is not posible to get one of the Properties of the User. But when I create a new Object with Set user = CreateObject("GuptaIntferface.UserVOCom") I can see all Properties of this object. My Question is now how can I tell VBA now that the objects in the List are the UserVOCOM Objects? thx for help Michael I'm kind of stabbing the dark on this one as I've never worked with a C...

Money Automatically Trying to Install whenever mouse is clicked
I have Money 2002 which came with my PC and was installed at time of order on my Windows XP Laptop. However, lately (this problem didn't occur until recently) whenever I try to open a new window of any sort in Windows, money is trying to re-install itself (even though its already installed and I keep telling it to cancel). How can I stop this? Thanks. Kelly >-----Original Message----- >I have Money 2002 which came with my PC and was installed >at time of order on my Windows XP Laptop. However, lately >(this problem didn't occur until recently) whenever I try ...

Delete macros
I am using Excel 2002. When I click on Tools->Macro->Macros... i see 2 macros. The problem I am having is that I can't delete these macros, the delete button to the right is grayed out. How can I delete these macros? Hi maybe the macros are protected. Try hitting ALT + F11 to open the VBA editor and try to delete the macros / modules there -- Regards Frank Kabel Frankfurt, Germany excel777 wrote: > I am using Excel 2002. When I click on Tools->Macro->Macros... i see > 2 macros. The problem I am having is that I can't delete these > macros, the delete button to ...

Automatically send email message when folder contents have changed.
Hoping someone can help. We have a UNIX server on our network and an Exchange 2003 server. Ideally we would like to have the Exchange server send an email to a group of users when a new file gets added to a shared folder on the UNIX box. The UNIX box is running VisionFS and we can see the shared folder in our Windows environment. Ideally I would like to have the Exchange server send a message without having to dedicate a PC running Outlook and a plug-in to the task but will do so if necessary. Any thoughts would be appreciated... Script it, schedule it to run on any member server (good i...

Automatic PO Re-Order
Is it Possible to generate Po using min/max re-order and not add the items already in transist on a previous Po? I need to generate from min levels only not the difference between Min. and what's on-order, to max level . -- Proink Clean up the PurchaseOrderEntry table - get rid of the entries you don't want in transit (note that it will also remove them from the prvious POs) "Proink" wrote: > Is it Possible to generate Po using min/max re-order and not add the items > already in transist on a previous Po? I need to generate from min levels only > not t...

deleting email in outlook, freezes before i can delete
i have a file with pics that symetec scanner says is to large. i can receieve email but cannot send any. it freezes before i can delete and says non responding. Hi All, I want to re-raise the old issue of Fax numbers showing up in the Outlook Address book when one is sending an email. I know that this can be stopped by prepending the Contact's fax number with a letter so that Outlook doesn't see it as a valid fax number and therefore doesn't list it. What's always puzzled me, however, is that this fix doesn't work if the fax numbers are changed using an export to CSV...

Go to the begining of the txt file after using getline()
Go to the begining of the txt file after using getline() I use fstream, open() and getline() to take a whole line from the text file. I would like to know how I can set the value of the file pointer to the beginning of the file without closing (with close() ) to start using getline() again. I need to do it many times and I think that making that without closing and reopening file thousands times will save much time. Could you advise me. Alur fseek(fileptr,0,SEEK_SET); AliR. "Alur" <Alur@discussions.microsoft.com> wrote in message news:CD7B7AFF-6057-4C37-955A-CADA73781B3...

Locate a specific row or column
Hi all, Could you tell me how to locate a specific row instead of using Mouse to dray the scroll bar? Clara thank you so much for your help In VBA code, you can use: Range("D100").Activate ' Or Range("D1:D100").Select ' Depending on if you want only one cell highlighted or a range of cells. -- Best wishes, Jim "clara" wrote: > Hi all, > > Could you tell me how to locate a specific row instead of using Mouse to > dray the scroll bar? > > Clara > > thank you so much for your help Hi Clara Have you tried goto in the Ed...

Possibility of use of the Microsoft CRM UI Controls in Customization
There are many dll files in wwwroot/bin directory. Is microsoft planing to expose dlls i.e UI controls for ISV customization later? they have not been exposed yet janet. also no word of any plans to do so "Janet" <jzou@menlogroup.com> wrote in message news:08d701c361ff$84c73b70$a301280a@phx.gbl... > There are many dll files in wwwroot/bin directory. Is > microsoft planing to expose dlls i.e UI controls for ISV > customization later? ...

OK to delete Deleted Items folder?
I'm afraid I'll have to delete my Deleted Items folder in Outlook 2000. When I try to empty the folder I get a "The messaging interfce has returned an unknown error. If the problem persists Restart Outlook" message. Is it possible to delete the entire folder and replace it with an empty new one? Will it create any problems? TIA Henrik Not possible. Run scanpst.exe against your pst-file to scan it for errors first. -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -What do the Outlook Icons Mean? -Create an Office 2003 CD slipstreamed with Se...

How to delete chart
I created a histogram and want to delete it. I select it and the faint double border apperars. There are no square handles like in 2003. Then I press the Delete key. The faint double border goes away replaced by a single thin black border. The chart is still there and is not able to be selected at all. I entered "delete chart" in the Excel Help window, and there was nothing at all on deleting a chart. Ditto for "remove chart." I got no help searching on the internet either. I have Excel 2007 and Windows XP Professional When the border changes, can you press Delete a...