问题
So I'm trying to find/make a program that will find all my duplicate words in excel. For example in A1 "someone" in A2 ""person" and ect but I'll have "someone" multiples times or another word and I need to condense that information together. But I need to do it in a way where I don't search manually to concatenate duplicates. So is there a way to find the duplicate words and concatenate them?
I have also been looking into doing it using "FIND" to look for them but it has yielded no luck yet. I also have been using the "FILTER" but I don't know a way to condense the duplicates without doing it manually. I also been wondering where you can find the code for functions like "FIND, REPLACE and ect."? If I could find that I could change the coding for "REMOVE DUPLICATES" to change it for words. But hey I don't really know if that really would work or not. Anything would help.
For example:
culomn1 - culomn2 -----culomn3
y ------ A -----(nothing)
z ------ B -----(nothing)
z ------ (nothing)-----I
x ------ (nothing)-----k
y ------ (nothing)-----j
x ------ C ------(nothing)
to this
culomn1 - culomn2 -----culomn3
y------A------j
z------B------I
x------C------k
except the letters are words.
回答1:
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!
回答2:
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))
回答3:
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.
回答4:
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
来源:https://stackoverflow.com/questions/18164851/is-there-way-to-find-duplicate-words