View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default String Comparison

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 7/2/2008 by Joel
'

'
RowCount = 1
Do While Range("B" & RowCount) < ""
If Range("B" & RowCount) < Range("C" & RowCount) Then

'copy cell B to column D
Range("D" & RowCount).Value = _
Range("B" & RowCount).Value
'highlight characters that are different
For i = 1 To Len(Range("D" & RowCount))
If Mid(Range("B" & RowCount), i, 1) < _
Mid(Range("C" & RowCount), i, 1) Then

Range("D" & RowCount). _
Characters(Start:=i, Length:=1).Font _
.ColorIndex = 41
End If
Next i
End If
RowCount = RowCount + 1
Loop
End Sub



" wrote:

Hi

I have 2 text strings of equal length (7) in the cells for columns B &
C. The strings in C differ slightly to those in B.

I am a novice at macros but would like some help in comparing column C
cells to B cells and returning the difference in Column D. i.e.
Compare C2 to B2 and return the difference in D2 and continue down the
rows until the end of the data.

The first row contains the column headings.

Any help wolud be much appreciated.

Thanks