Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Search Search
Search for:
Tech Support Guy > > >

Excel VBA Macro to delete rows/columns with criteria


(!)

anamque's Avatar
anamque anamque is offline
Junior Member with 29 posts.
THREAD STARTER
 
Join Date: May 2010
Experience: Beginner
09-Jul-2010, 08:39 AM #1
Cool Excel VBA Macro to delete rows/columns with criteria
Hello - I found a previous post on this site that solves (I think) 90% of what I need to accomplish. I have a large spreadsheet that I need to:

Delete column C
Delete all rows without account numbers (Acct numbers will always be in column A)
Delete all rows that have dates in column F other than “00/00/0000”.

The code I found on this site is :

Simple vba code:
lastrow = Range( "A65536").end(xlup).row
For y = LastRow To 2 Step -1
If Cells(y, x).Value = "" Then Cells(y, x).Delete shift:=xlUp
Next y
Set the range to the the column desired, in this case "A"
Lastrow checks the last row and starts from the end up.
Removes all empty rows entirely up to row 2 because row 1 generally is the header
Happy coding


Can anyone help me?
turbodante's Avatar
turbodante turbodante is offline
Senior Member with 744 posts.
 
Join Date: Dec 2008
Location: GMT UK
15-Jul-2010, 02:59 AM #2
To delete column c, use:

Code:
Columns("E").EntireColumn.Delete


Delete all rows without account numbers (Acct numbers will always be in column A)
and
If Cells(y, "A").Value = "" Then Cells(y, "A").Delete shift:=xlUp

Use:

Code:
lastrow = cells(rows.count,1).end(xlup).row
For y = LastRow To 2 Step -1
If  Cells(y, "A").Value = "" Then Rows(y).EntireRow.Delete 
If  Cells(y, "F").Value =  00/00/0000 Then Rows(y).EntireRow.Delete ' Delete all rows that have dates in column F other  than 00/00/0000.
Next y




As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


Tags
delete columns, delete rows, excel 07

(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Title Thread Starter Forum Replies Last Post
Solved: move data from rows and columns to other rows and columns kf4fzr Business Applications 3 06-Jul-2010 03:40 AM
Simple Excel Macro to Copy Row from one Sheet to Another exterminar Business Applications 1 14-Aug-2009 04:27 AM
Need help with an excel macro to delete row within a set range johnm524 Business Applications 8 29-Apr-2009 09:30 AM
delete rows not matching multiple criteria jsimms001 Business Applications 13 16-Oct-2008 01:31 PM
Excel HELP macro to Delete Row Based 2 columns from 2 sheets shimbardy Business Applications 1 03-Sep-2008 05:06 PM

WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑

Content Relevant URLs by vBSEO 3.3.2