我不認爲有一個函數可以解答你的問題。
我做了一個小腳本,將比較兩個單元格,測試它,把你的值在Range("A1")
和Range("A2")
。因爲你只比較兩個值,所以這樣循環將具有非常小的性能影響。
Sub d()
Dim ValueOne As String
Dim ValueTwo As String
Dim charVal
Dim sString
Dim char
Dim boolVal As Boolean
ValueOne = Cells(1, 1).Value
ValueTwo = Cells(2, 1).Value
boolVal = True
If Len(ValueTwo) = Len(ValueOne) Then
charVal = StrConv(ValueOne, vbUnicode)
charVal = Left(charVal, Len(charVal) - 1)
sString = Split(charVal, Chr(0))
For Each char In sString
If Len(ValueTwo) = Len(Replace(ValueTwo, char, "")) Or Len(Replace(ValueTwo, char, "")) <> Len(Replace(ValueOne, char, "")) Then
boolVal = False
GoTo nxt
End If
Next
charVal = StrConv(ValueTwo, vbUnicode)
charVal = Left(charVal, Len(charVal) - 1)
sString = Split(charVal, Chr(0))
For Each char In sString
If Len(ValueOne) = Len(Replace(ValueOne, char, "")) Or Len(Replace(ValueTwo, char, "")) <> Len(Replace(ValueOne, char, "")) Then
boolVal = False
GoTo nxt
End If
Next
Else
boolVal = False
End If
nxt:
If boolVal = False Then
MsgBox "Strings are different"
Else
MsgBox "Strings are the same"
End If
End Sub
另外,如果你想這是一個功能,你可以很容易地改變成一個剛剛做這個,
Function Compare(ValueOne As String, ValueTwo As String)
Dim charVal
Dim sString
Dim char
Dim boolVal As Boolean
' Insert same code as above here
'End Insert same code as above here
If boolVal = False Then
Compare = True
Else
Compare = True
End If
End Function
這是這種情況嗎?你有不同的國家,中間有一個';'? –
嗨,, 不,這並非總是如此。這只是一個例子,單元格可以具有任何價值而沒有固定模式。 – Ckn
如果你在單元格中有其他角色,你怎麼知道你想'日本;美國'或其他方式呢? – KyloRen