[英]Check if there exists in an Excel sheet a string of length within several strings in cell
I would like to see if there exists a string of length 25 in a certain cell. 我想查看某个单元格中是否存在长度为25的字符串。 The problem is that the cell I want to check, contains several strings seperated by a space.
问题是我要检查的单元格包含多个由空格分隔的字符串。 Of these strings, I want to know if there is a string of length 25.
在这些字符串中,我想知道是否有长度为25的字符串。
If I use for example the LEN-function, I get the total length of the strings in the cell, while I want to see if there indeed exists a string of length 25 between all the strings in that cell. 例如,如果使用LEN函数,我将获得单元格中字符串的总长度,而我想查看该单元格中所有字符串之间是否确实存在长度为25的字符串。
You need to split the string into separate strings to use Len
so use Split
and loop through the array of strings. 您需要将字符串拆分为单独的字符串才能使用
Len
因此请使用Split
并遍历字符串数组。 This is the code for a single cell check: 这是单个单元格检查的代码:
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.