Re: Finding words with capital letters and numbers in them
- From: "Rick Rothstein \(MVP - VB\)" <rickNOSPAMnews@xxxxxxxxxxxxxxxxx>
- Date: Thu, 29 Nov 2007 17:39:14 -0500
As for the missing first letter... that's what happens when you rush. My brother is due any minute for dinner, so I had to get ready... I made a last minute change from my original delimiter of a comma-space to just the space that you used and I forgot to adjust the code for the length difference. I change my code to include a Delimiter constant (set to equal a space; but changeable to any combination of characters) and put code in to account for it. As for the multi-line problem... I never even gave it a thought originally. Below is a revised function that handles both problems (thanks for catching them)...
Function GetCapWords(R As Range) As String
Dim X As Long
Dim Words() As String
Const Delimiter = " "
Words = Split(Replace(Replace(R.Value, vbLf, " "), vbCr, " "))
For X = 0 To UBound(Words)
If Words(X) = UCase(Words(X)) Then
GetCapWords = GetCapWords & Delimiter & Words(X)
End If
Next
If Len(GetCapWords) > 0 Then
GetCapWords = Mid(GetCapWords, 1 + Len(Delimiter))
End If
End Function
Rick
"Ron Rosenfeld" <ronrosenfeld@xxxxxxxxxx> wrote in message news:n5buk3hmqjv7qele8iu976rhebaubp7kqf@xxxxxxxxxx
On Thu, 29 Nov 2007 15:39:15 -0500, "Rick Rothstein \(MVP - VB\)"
<rickNOSPAMnews@xxxxxxxxxxxxxxxxx> wrote:
Function GetCapWords(R As Range) As String
Dim X As Long
Dim Words() As String
Words = Split(R, " ")
For X = 0 To UBound(Words)
If Words(X) = UCase(Words(X)) Then
GetCapWords = GetCapWords & " " & Words(X)
End If
Next
If Len(GetCapWords) > 0 Then
GetCapWords = Mid(GetCapWords, 3)
End If
End Function
What surprises me a little, Ron, is that it looks shorter than the RegEx
solution... not what I would have expected.
Rick,
Given this string:
The TKRTC value in the 765TW field is not the default
Your routine, on my machine, returns:
KRTC 765TW
(The initial T is missing)
Also, given a multiline string:
The TKRTC
value in the 765TW field is not the default
(with no space after TKRTC), your routine returns:
65TW
missing TKRTC and also again missing the first character.
--ron
.
- Follow-Ups:
- Re: Finding words with capital letters and numbers in them
- From: Ron Rosenfeld
- Re: Finding words with capital letters and numbers in them
- References:
- Finding words with capital letters and numbers in them
- From: Raj
- Re: Finding words with capital letters and numbers in them
- From: Ron Rosenfeld
- Re: Finding words with capital letters and numbers in them
- From: Rick Rothstein \(MVP - VB\)
- Re: Finding words with capital letters and numbers in them
- From: Ron Rosenfeld
- Finding words with capital letters and numbers in them
- Prev by Date: Re: Searching
- Next by Date: Re: Copy range from one workbook to another
- Previous by thread: Re: Finding words with capital letters and numbers in them
- Next by thread: Re: Finding words with capital letters and numbers in them
- Index(es):
Relevant Pages
|