Pick Another word

Np72

Board Regular
Joined
Dec 22, 2010
Messages
108
Hi,

I have this coding (which I've modified for my own purpose) and I wanted to add more words i.e. current Account (Vm) and Current account (VI). I've gone down the road of filtering then deleting but it just looks........messy ! Is there a way of adding these 2 current Account (Vm) and Current account (VI) into the coding.

Many Thanks

Sub FindAndRemove()
Dim i As Long
Dim j As Long
Dim pickWord As Variant
Dim pickAnother As Variant
pickWord = "margin"
pickAnother = "standard class"

For i = 2 To Range("B" & Rows.Count).End(xlUp).Row
Set w = Range("B" & i).Find(pickWord, LookIn:=xlValues)
Set y = Range("B" & i).Find(pickAnother, LookIn:=xlValues)
If w Is Nothing And y Is Nothing Then
Rows(i).EntireRow.Delete
If Range("B" & i) = "" Then Exit Sub
i = i - 1
End If
Next i


End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hello

What Excel version do you use?
 
Upvote 0
Anyway, try:

Code:
Sub wigi()

    Dim i As Long
    
    Application.ScreenUpdating = False
    
    On Error Resume Next
    
    vWords = Array("margin", "standard class", "current Account (Vm)", "Current account (VI)")


    With Cells(1).CurrentRegion.Columns(2)
        sq = .Value
        For i = 2 To UBound(sq)
            If IsError(WorksheetFunction.Match(sq(i, 1), vWords, 0)) Then sq(i, 1) = ""
        Next
        .Value = sq
        .SpecialCells(4).EntireRow.Delete
    End With


End Sub
 
Upvote 0
Hi.

Thanks for this and apologies for my delay in replying. I'm on 2007, I've used this coding and keep getting a sub or function not defined error, so am in the process of figuring this out
 
Upvote 0
Hi,

Sussed it, but the macro is now deleting the whole sheet and not leaving Array("margin", "standard class", "current Account (Vm)", "Current account (VI)")
 
Upvote 0
Hi,

Actually as a slight spin on this, what if I wanted to have this as like margin", "standard class", "current Account (Vm)", "Current account (VI)")
 
Upvote 0
I don't understand what you are asking now. Sorry.
 
Upvote 0
Instead of looking for those particular words can it look for words like current Account (Vm)", "Current account (VI)")

for example it would locate words like EUR Current account (VM), GBP Current account (VM). Not just Current account (VM) or (VI). I tried vWords = Array("margin", "standard class", "*current Account (Vm)*", "*Current account (VI)"*)

Using wildcards to find part of the text

but this didnt work
 
Last edited:
Upvote 0
Hello

This is more tricky. For example:

Code:
Sub wigi()

    Dim i As Long


    Application.ScreenUpdating = False


    On Error Resume Next


    vWords = Array("margin", "standard class", "current Account (VM)", "Current account (VI)")


    With Cells(1).CurrentRegion.Columns(2)
        .Parent.Parent.Names.Add "wigi", vWords
        sq = .Value
        For i = 2 To UBound(sq)
            If IsError(Evaluate("LOOKUP(2^15,SEARCH(wigi,""" & sq(i, 1) & """))")) Then sq(i, 1) = ""
        Next
        .Value = sq
        .SpecialCells(4).EntireRow.Delete
    End With


End Sub
 
Upvote 0

Forum statistics

Threads
1,216,297
Messages
6,129,954
Members
449,544
Latest member
Akhil333

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top