例子:
如果我在 A1 中有:apple、Orange、Grapes 我希望在 B1:Pineapple、Maa 中缺少名稱。
如果 A2:葡萄,菠蘿,那么我會在 B2:蘋果,橙,瑪
我在網上搜索了一個解決方案,但我發現只有缺少數字的相同型別。請幫忙解決這個問題
如果我能在這里找到解決方案,我會很高興。謝謝。
我累了以下:
Public Function MissingWords As String
Dim temp As String
Temp = Replace (stringList, "")
temp = Replace(temp, "")
Dim arr As Variant
Arr = Split (temp, ", ")
Dim newstrings As String
Newstrings = " Apple,Orange,grapes,pineapple, maa"
Dim i As Long
For i = LBound (arr) To UBound(arr)
Newstrings = Replace (newstrings, arr(I) & ", ", "")
Next
Newstrings = Left$(newstrings, Lena(newstrings) - 1)
Missingstrings = newstrings
End function
如果我在 excel 中應用這個得到值錯誤
uj5u.com熱心網友回復:
在作業表中使用以下函式,如
=GetMissingWordsFromList(A1,"Apple,Orange,Grapes,Pineapple,Maa")
如果A1是,Pineapple,Maa你會得到Apple,Orange,Grapes回報。
請注意,這是區分大小寫,Pineapple并且pineapple不被認為是相同的。逗號后也不能有任何空格,,因為它無法處理。
Option Explicit
Public Function GetMissingWordsFromList(ByVal Words As String, ByVal WordsList As String, Optional ByVal Delimiter As String = ",") As String
Dim WordsArr() As String
WordsArr = Split(Words, Delimiter)
Dim WordsListArr() As String
WordsListArr = Split(WordsList, Delimiter)
Dim RetVal As String
Dim Word As Variant
For Each Word In WordsListArr
If Not IsInArray(Word, WordsArr) Then
RetVal = RetVal & IIf(RetVal = vbNullString, "", ",") & Word
End If
Next Word
GetMissingWordsFromList = RetVal
End Function
Private Function IsInArray(ByVal What As String, ByVal InArray As Variant) As Boolean
IsInArray = IsNumeric(Application.Match(What, InArray, 0))
End Function
使其不區分大小寫(因此它會Pineapple,Maa在串列中找到apple,orange,grapes,pineapple,maa),您需要使用
WordsArr = Split(LCase(Words), Delimiter)
和
If Not IsInArray(LCase(Word), WordsArr) Then
反而。
uj5u.com熱心網友回復:
您的功能的最后一行應該是
MissingWords=NewStrings
現在,您的函式始終不回傳任何內容。Missingstrings 未在函式中定義。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/366810.html
