How to Count the Number of a Specific Character in a Cell with Excel VBA

前端 未结 6 831
忘掉有多难
忘掉有多难 2021-01-14 22:26

I have a number of items in cells that are separated by dashes. I\'m trying to normalize the database by splitting rows so that each row contains only one entry. How do you

6条回答
  •  逝去的感伤
    2021-01-14 22:48

    I found this answer:

    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 
    

提交回复
热议问题