我在单元格中有许多用破折号分隔的项目。我试图通过拆分行来规范数据库,以便每行只包含一个条目。如何在Excel中查找/计数字符串。我知道你可以为整个细胞做值
myVar = Application.WorksheetFunction.COUNTIF(Range("A1:Z100"),"Value")我需要搜索一个单元,找出有多少连字符。示例
123-456-789 = 2
9876-12 = 1发布于 2015-03-18 01:44:58
使用上面ron's function的提示,我创建了这个公式,它运行得很好:
=LEN(A1) - LEN(SUBSTITUTE(A1, "-", ""))发布于 2014-01-27 03:15:13
这将计算活动单元中连字符的数量。
Sub test()
a = Len(ActiveCell)
my_txt = Replace(ActiveCell, "-", "", 1, -1, vbTextCompare)
b = Len(my_txt)
numb_occur = a - b
End Sub发布于 2016-04-10 04:28:03
我找到了这个答案:
Sub xcountCHARtestb()
'If countCHAR(RANGE("aq528"), ".") > 0 Then 'YES
If countCHAR(Selection, ".") > 0 Then 'YES
MsgBox "YES" & Space(10), vbQuestion ', "title"
Else
MsgBox "NO" & Space(10), vbQuestion ', "title"
End If
End Sub
Sub xcountCHARtesta() 'YES
MsgBox "There are " & countCHAR(Selection, "test") & " repetitions of the character string", vbQuestion 'YES
End Sub
Function countCHAR(myString As String, myCHAR As String) As Integer 'as: If countCHAR(Selection, ".") > 1 Then selection OR RANGE("aq528") '"any char string"
countCHAR = UBound(split(myString, myCHAR)) 'YES
End Function https://stackoverflow.com/questions/21371817
复制相似问题