View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
ion ion is offline
external usenet poster
 
Posts: 12
Default VBA for comparing sequences of characters.

Antonio,
The text format belongs to the range, not the characters. So, you'd
have to assign one character per cell.
rng.cells(lpos).value = mid(sFirst, lPos, 1)
rng.cells(lPos).Font.Bold = (mid(sFirst, lPos, 1) = mid(sSecond, lPos,
1))
hth
Ion

a.riva@UCL wrote:
Hello!

I would like to know how can I write a VBA macro to execute the
following.
Given two strings of characters having the same length, I need a
function that compares each couple of characters in the same position
of the initial strings and gives back as a result a string equal to the
first input string but with the characters, that are different compared
with input string number two, written in bold font.

Example:

string1: A B C D E F
string2: A B C W E F

result of the formula: A B C [bold]D E F

since the first positions are both A, the second positions are both B,
the third are both C, the fifth are both E and the sixth are both F.
BUT the fourth positions differ, and so I can highlight that in string
1 there is the fourth position changed.

How can I write the code? I can easily use the Mid function to extract
the characters in each position, under a loop with "i" changing from 1
to the length of the sequences (with the Len function). But I don't
know how to change the style of the font if the character is different
between string1 and string2...

Can somebody help me?

Thank you very much!!!

Antonio Riva.