I'm trying to count the number of occurnaces of a character within a cell to use as criteria within an If statement in a Macro.... For example
Hi/This is/ Randy
Hi/this is Randy
I'd like to count the number of "/" within the cell 2 for the first, 1 for the second.
Hmm.. Unless I'm missing something I don't appear to be able to use Substitue within a Visual Basic Macro to use this? Otherwise I think it would work. I.e...
VB:If LEN(A1)-LEN(SUBSTITUTE(A1,"/","")) >1 Then Exit For End If
Hope this makes sense.
Last edited by Dave Hawley; August 23rd, 2006 at 12:44.
VB:If Len([a1]) - Len(Replace([a1].Value, "/", "")) > 1 Then Exit For End If
PLEASE use the code tags for any code as you agreed. I think you should read the rules you have agreed to, don't you?
VB:Sub CountChar() MsgBox Len(Range("A1")) - Len(Replace(Range("A1"), "/", "")) End Sub
Sorry rtgleck, did read the in Macro part of the question.
Well... actually you can use it in VBA the same way you'd use it in a worksheet cell. That is, if you wanted to...Originally Posted by rtgleck
VB:Sub test() x = [Len(A1) - Len(Substitute(A1, "/", ""))] If x > 1 Then MsgBox x End If End Sub
Sub All_Macros(Optional control As Variant)
There are currently 1 users browsing this thread. (0 members and 1 guests)