[英]Count the same number of characters between two cells in Excel
I'm pretty new, not a first time user, but maybe been here once before. 我是新手,不是第一次来,但也许以前来过这里。
I have a huge list of names to check if they have duplicates. 我有大量的名称列表,以检查它们是否重复。
The problems is that sometimes the same name is spelled differently for the same person in the list. 问题在于,有时列表中的同一人的名字拼写不同。
So, I'd like to check the first letters of a cell to see if they are the same. 因此,我想检查一个单元格的前几个字母是否相同。
For example, here's a made-up list: 例如,这是一个虚构列表:
A1 John Doe
A2 John Dowe
A3 John Dove
Is there an Excel function I can use that will tell me how many characters are the same from the cell above it? 我可以使用一个Excel函数来告诉我上面的单元格中有多少个字符吗?
So, in the example above the cells where the formula would be, would display: 因此,在上面的示例中,公式所在的单元格将显示:
A1 John Doe B1 0 (or "NA" or "REF" because there's no cell to compare to above it)
A2 John Dowe B2 7
A3 John Dove B3 7
Because both A2 and A3 share 7 characters with the cell above them... I hope this is easy to understand. 因为A2和A3都与它们上方的单元格共享7个字符,所以我希望这易于理解。
Thanks! 谢谢!
Take a look at this question . 看一下这个问题 。 It's asking about name matching under a different situation, but there are plenty of good examples of how to do it listed there.
它询问有关在不同情况下进行名称匹配的问题,但是在那里列出了很多很好的示例。
It's a pretty deep rabbit hole depending on how intense and in-depth you want to get. 这是一个非常深的兔子洞,具体取决于您想要获得的强度和深度。
You are NOT giving us enough info. 您没有给我们足够的信息。
In your case, A1 ("John Doe") contains two "o" characters. 在您的情况下,A1(“ John Doe”)包含两个“ o”字符。 Because of that, the cell below, A2 ("John Dowe") will have only 6 characters in common.
因此,下面的单元格A2(“ John Dowe”)将只有6个字符。
IF what you mean by "same character" is same character in the same position, then you still have got a problem, between A1 and A2. 如果您所说的“相同字符”是在相同位置的相同字符,那么在A1和A2之间仍然存在问题。
John Do e 约翰·做电子商务
John Do w e 约翰待办事项宽 E
"w" and "e" don't match. “ w”和“ e”不匹配。 Only 6 characters is same.
只有6个字符相同。
Provides us more info! 为我们提供更多信息!
EDIT #1 编辑#1
Copy and paste this code in the Module 将此代码复制并粘贴到模块中
Function compareCells(ran As Range) As Variant
Dim numSame As Integer
Dim c As Integer
Dim r As Integer
c = ran.Column 'find selected column
r = ran.Row 'find selected row
Dim a As String
Dim b As String
a = Worksheets("Ark1").Cells(r - 1, c).Value 'string of the cell above
b = Worksheets("Ark1").Cells(r, c).Value 'string of the current cell
Dim aLen As Integer
aLen = Len(a) 'check the length of the a string
Dim i As Integer
For i = 1 To aLen
If Mid(a, i, 1) = Mid(b, i, 1) Then 'if chars in same pos are equal...
numSame = numSame + 1
End If
Next
compareCells = numSame
End Function
EDIT #2 编辑#2
Function compareCells(ran As Range) As Variant
Dim numSame As Integer
Dim c As Integer
Dim r As Integer
c = ran.Column 'find selected column
r = ran.Row 'find selected row
Dim a As String
Dim b As String
a = ActiveSheet.Cells(r - 1, c).Value 'string of the cell above
b = ActiveSheet.Cells(r, c).Value 'string of the current cell
Dim aLen As Integer
aLen = Len(a) 'check the length of the a string
Dim i As Integer
For i = 1 To aLen
If Mid(a, i, 1) = Mid(b, i, 1) Then 'if chars in same pos are equal...
numSame = numSame + 1
End If
Next
compareCells = numSame
End Function
Use =compareCells()
and select only the cell you want to compare with the cell above 使用
=compareCells()
并仅选择要与上面的单元格进行比较的单元格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.