View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default search for any lowercase immediately followed by an UPPERCASE

Hi,

Two macros slightly different. They only process one string. Can you handle
writing the code for a loop to repeat for all cells down the page?

The following does exactly as requested:-

Sub Search_String()

Dim strToSearch As String
Dim strFound1 As String
Dim strFound2
Dim lgthString As Long
Dim strNew As String
Dim i As Long

strToSearch = Range("A1")

lgthString = Len(strToSearch)

'Assign first character to new string
strNew = Left(strToSearch, 1)

'Start search from second character
For i = 2 To lgthString
strFound1 = Mid(strToSearch, i, 1)

'test for uppercase
If strFound1 = "A" And strFound1 <= "Z" Then

'If uppercase, test next character for lower case
strFound2 = Mid(strToSearch, i + 1, 1)
If strFound2 = "a" And strFound2 <= "z" Then
strNew = strNew & "," & strFound1
Else
strNew = strNew & strFound1
End If
Else
strNew = strNew & strFound1
End If
Next i

'Ensure that the following range is blank
'so as not to overwrite data
Range("B1") = strNew


End Sub

The following places a comma before every uppercase character:-

Sub Search_String_2()

Dim strToSearch As String
Dim strFound1 As String
Dim lgthString As Long
Dim strNew As String
Dim i As Long

strToSearch = Range("A1")

lgthString = Len(strToSearch)

strNew = Left(strToSearch, 1)
For i = 2 To lgthString
strFound1 = Mid(strToSearch, i, 1)
If strFound1 = "A" And strFound1 <= "Z" Then
strNew = strNew & "," & strFound1
Else
strNew = strNew & strFound1
End If
Next i

'Ensure that the following range is blank
'so as not to overwrite data
Range("C1") = strNew


End Sub

Regards,

OssieMac



" wrote:

Can someone help me create a macro that will search for a lowercase
letter immediately followed by an uppercase letter and then insert a
character in between? I can then do a text to columns to split them
up...I've got a bunch of text that got jammed together.

thanks very much!!