![](/img/trans.png)
[英]check if string exists within two lists of strings (separated by commas)
[英]Check if there exists in an Excel sheet a string of length within several strings in cell
我想查看某個單元格中是否存在長度為25的字符串。 問題是我要檢查的單元格包含多個由空格分隔的字符串。 在這些字符串中,我想知道是否有長度為25的字符串。
例如,如果使用LEN函數,我將獲得單元格中字符串的總長度,而我想查看該單元格中所有字符串之間是否確實存在長度為25的字符串。
您需要將字符串拆分為單獨的字符串才能使用Len
因此請使用Split
並遍歷字符串數組。 這是單個單元格檢查的代碼:
Dim WrdArray() As String
Dim TestLen As Integer
' Get the cell and split it into separate strings in an array
WrdArray() = Split(Range("A1"))
' Loop the strings array to find any that equal 25 characters long
For i = LBound(WrdArray) To UBound(WrdArray)
TestLen = Len(WrdArray(i))
If (TestLen = 25) Then
MsgBox "found one"
End If
Next i
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.