Is there way to find duplicate words?

╄→гoц情女王★ 提交于 2019-12-06 13:56:28
Our Man in Bananas

I don't know if you could do this with formulas in Excel unless you know what word you are looking for within the cell. You could try either a UDF, or a Regular Expression.

my question and answer with links might get you started:

StackOverflow: formula to see if a surname is repeated within a cell

and maybe:

VBA Express

Once you've posted your Excel worksheet with data we see if I've got it wrong!

You could use advanced filter to copy unique values from column 1 to a new column. Then you would use a vlookup formula to get the rest.

Assumptions:

  • Row 1 is a header row so actual data starts in row 2
  • Column1 is column "A"
  • Column2 is column "B"
  • Column3 is column "C"
  • The new column with the unique values is column "E".

In cell F2 and copied over to G2 and then down as needed:

=INDEX(INDEX($B$2:$C$7,0,COLUMNS($E2:E2)),MATCH(1,INDEX(($A$2:$A$7=$E2)*(INDEX($B$2:$C$7,0,COLUMNS($E2:E2))<>""),),0))

Sheet1 Before:

Code:

Sub Macro1()

    With Sheet1
        .Columns("A:A").AdvancedFilter Action:=xlFilterCopy, _
            CriteriaRange:=.Range("F1:F2"), CopyToRange:=.Range("K1"), Unique:=True
        .Columns("B:B").AdvancedFilter Action:=xlFilterCopy, _
            CriteriaRange:=.Range("G1:G2"), CopyToRange:=.Range("L1"), Unique:=True
        .Columns("C:C").AdvancedFilter Action:=xlFilterCopy, _
            CriteriaRange:=.Range("H1:H2"), CopyToRange:=.Range("M1"), Unique:=True
    End With

End Sub

Sheet1 After:

make sure field names are used.

This will give you a function that will find the first non-blank cell against a specific string

Option Explicit

Function NonBlankLookup(SearchTxt As String, LookIn As Range, OffSetRows As Long) As Variant
Dim loc As Range
Dim FirstFound As Range

Set loc = LookIn.Find(what:=SearchTxt)
While Not (loc Is Nothing)
    If Not IsEmpty(loc.Offset(0, OffSetRows)) Then
        NonBlankLookup = loc.Offset(0, OffSetRows).Value
        Exit Function
    End If
    If FirstFound Is Nothing Then
        Set FirstFound = loc
    ElseIf loc = FirstFound Then
        NonBlankLookup = CVErr(2000)
        Exit Function
    End If
    Set loc = LookIn.Find(what:=SearchTxt, after:=loc)
Wend
NonBlankLookup = CVErr(2000)
End Function

to use, insert this code into a module, then in your excel spreadsheet, you can use a formula like =NonBlankLookup(E1,$A$1:$A$6,1) which will search for your text in A1:A6, and check 1 column to the right. If no text is found that matches the search string, or if the text is found but no data exists in the specified column, #NULL! is returned.
This also has a slight advantage to vlookup, as it will allow negative offset, so you could have the search text in column 2, and by using -1 for the offset, you could return data from column 1

Just so you are aware, because of the way that .find works, when you specify a range, it will start at the 2nd cell, and go down, and search the first cell you give it last.
e.g. with my example of A1:A6, it will search A2,A3,A4,A5,A6 and finally A1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!