Hereafter is a macro (VB6) that converts 2 adjacent lowercase consonants into the 1st remaining in lowercase and the 2nd converted into uppercase. Well, so far so good, but the problem is that it works only when both consonants are the same, i.e. cc, ll, pp, ss, etc. become cC, lL, pP, sS, etc. respectively. That's OK and that's what I want, but I also want two different adjacent consonants (any combination) to be converted the same way, i.e. ct, cz, mp, sz, etc. to become cT, cZ, mP, sZ, etc.

Any solution, please?


Dim SearchArray As Variant: Dim myRange As Range: Dim i As Long:
Dim pFind As String: Dim pReplace As String

SearchArray = Array("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", _
"r", "s", "t", "v", "w", "x", "y", "Z", "ç", "ñ", _
ChrW(&H161), ChrW(&H9E), ChrW(&H107), ChrW(&H10D), ChrW(&H11F), ChrW(&H142), ChrW(&H144), ChrW(&H148), ChrW(&H155), _
ChrW(&H159), ChrW(&H15B), ChrW(&H15F), ChrW(&H163), ChrW(&H17A), ChrW(&H17C), ChrW(&H158), ChrW(&H123), ChrW(&H137), _
ChrW(&H13C), ChrW(&H146), ChrW(&H10F), ChrW(&H165))

ReplaceArray = Array("B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", _
"R", "S", "T", "V", "W", "X", "Y", "Z", "Ç", "Ñ", _
ChrW(&H160), ChrW(&H8E), ChrW(&H106), ChrW(&H10C), ChrW(&H11E), ChrW(&H141), ChrW(&H143), ChrW(&H147), ChrW(&H154), _
ChrW(&H158), ChrW(&H15A), ChrW(&H15E), ChrW(&H162), ChrW(&H179), ChrW(&H17B), ChrW(&H142), ChrW(&H122), ChrW(&H136), _
ChrW(&H13B), ChrW(&H145), ChrW(&H10E), ChrW(&H164))

Set myRange = ActiveDocument.Range: For i = LBound(SearchArray) To UBound(SearchArray)
pFind = SearchArray(i) + SearchArray(i): pReplace = SearchArray(i) + ReplaceArray(i)
With myRange.Find: .Text = pFind: .Replacement.Text = pReplace: .Execute Replace:=wdReplaceAll
End With: Next

are they always 2 characters?
is the first one always the lower one?

you can try LCASE(<string>) to change to lowercase or UCASE(<String>) to change to capitals, mix this with the left and right function.

Changecase = "cz"

Changecase = Lcase(Left(changecase,1)) & Ucase(Right(changecase,1))

If I'm on the wrong track let me know

Thank you Bushman_222 for your reply

your questions:

are they always 2 characters?: Yes
is the first one always the lower one? Yes

I changed the original pFind = SearchArray(i) + SearchArray(i): pReplace = SearchArray(i) + ReplaceArray(i) into pFind = SearchArray(i) & SearchArray(i): pReplace = (Left(SearchArray(i), 1)) & (Right(ReplaceArray(i), 1)) But the macro keeps converting as in the original, i.e. only when both consonants are
the same (cc --> cC, mm --> mM, pp --> pP, etc.)

if I use pFind = SearchArray(i) & SearchArray(i): pReplace = LCase(Left(SearchArray(i), 1)) & UCase(Right(SearchArray(i), 1)) it does not convert characters above code 256.

I don't under stand what your code is doing can you break it down for me.

pFind = SearchArray(i) & SearchArray(i)
pReplace = LCase(Left(SearchArray(i), 1)) & UCase(Right(SearchArray(i), 1))

Hi Bushman_222,

Again thank you for helping me and for your patience.

Er... although I understand the verb "break down", I don't quite grasp. Anyway, I'll do my best.

pFind = SearchArray(i) is the first lowercase consonant,
& SearchArray(i) is the second lowercase consonant
to be converted to
pReplace = LCase(Left(SearchArray(i), 1)) the first consonant to remain in lowercase
& UCase(Right(SearchArray(i), 1)) the second consonant in uppercase
As I said, it works only when both consonants are the same and does not convert characters above code 256.

While pFind = SearchArray(i) & SearchArray(i): pReplace = (Left(SearchArray(i), 1)) & (Right(ReplaceArray(i), 1)) converts characters above code 256 as well and only when both consonants are the same.

Regards.

I'm afraid that I'm stummped on this one, only can think of a work around, ie make it all lower case first.


Hope that someone else can help more

That's all right Bushman_222

Thank you for spending your time and thank you for your effort.

Regards

This article has been dead for over six months. Start a new discussion instead.