Hello,
I have created the below macro code to delete all the rows containing "account" in column B.
Can you please help me using the below VBA codes, using IF...THEN condition.
Range("B1").Select Selection.AutoFilter Field:=1, Criteria1:="=*account*", Operator:=xlAnd Range(Selection, Selection.End(xlDown)).Select Selection.Delete Shift:=xlUp
Last edited by mohan_rajun; 10-25-2010 at 06:44 AM.
This is how I would write that:
Dim LR as Long Range("B1").AutoFilter Range("B1").AutoFilter Field:=1, Criteria1:="=*account*" LR = Range("B" & Rows.Count).End(xlUp).Row If LR > 1 Then Range("B2:B" & LR).Delete xlShiftUp ActiveSheet.AutoFilterMode = False
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Try this
Sub DeleteAccountRows() Dim RowCtr As Double Dim LastRow As Double LastRow = Cells(Rows.Count, "B").End(xlUp).Row For RowCtr = 1 To LastRow If InStr(Cells(RowCtr, "B"), "account") > 0 Then Rows(RowCtr & ":" & RowCtr).Delete Shift:=xlUp End If Next RowCtr End Sub![]()
Because you are shifting deleted rows up it might be better to count backwards instead of forwards. Change the For line to:
For RowCtr = LastRow to 1 Step -1
I would advise you read through: http://www.xtremevbtalk.com/showpost...70&postcount=4
ie if you intend to use AutoFilter then utilise SpecialCells etc...
edit: full tutorial link: http://www.xtremevbtalk.com/showthread.php?t=300757
Last edited by DonkeyOte; 10-25-2010 at 03:06 AM.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
I think the Jerry's code will work quicker but may have a problem if there are blank rows.
Excel people always assume users put data in well defined tables or lists.
Thanks for the link. I study now.
Hi JBeaucaire,
Thanks for the help... It worked out....
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks