×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Autofilter and Delete

Autofilter and Delete

Autofilter and Delete

(OP)
I would like to Autofilter an Excel worksheet based on criteria and delete the visible rows. I know Excel VBA has such capability.

Link

Can you help me in writing such code in VBScript?

RE: Autofilter and Delete

Hi,

Turn on your macro recorder and record the process of
1) SELECTing all the ROWs of data
2) FILTERing the ROWs you want DELETEd
3) DELETE
4) unFILTER

Turn off your recorder and Alt+F11 to activate the VB Editor. COPY the recorded code and PASTE here for help customizing.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: Autofilter and Delete

(OP)
I have figured out a solution. Here is the attached code.

CODE --> VBScript

const xlUp = -4162
lastRow = ws1.UsedRange.Rows.Count
lastColumn = ws1.UsedRange.Columns.Count

Set rngDataBlock = ws1.Range(ws1.Cells(1,1),ws1.Cells(lastRow,lastColumn))

rngDataBlock.AutoFilter 4,"a",,,False

If ws1.Cells(1,4).Value = "a" Then
	ws1.AutoFilter.Range.Delete xlUp
Else
	ws1.AutoFilter.Range.Offset(1).Delete xlUp
End If

ws1.AutoFilterMode = False 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close