On Tue, 22 Oct 2013 15:26:45 +0200, "Claus Busch" <claus_busch@t-
online.de> wrote in article said:
Hi Christine,
Am Tue, 22 Oct 2013 15:13:13 +0200 schrieb Claus Busch:
a bit faster:
Sub Test2()
snip
Regards
Claus B.
Hi Claus
This is good. But I wanted the marking on each of the cells, also
there are features I wanted to change: if the wrong word is a repeated
word then the hilight doesnt work, test4 below. And if the number of
words are different then not all is captured - tests 2, 3.
tests:
1 this is an elephant this isnt an elefant
2 i wondered lonely as a clewd i wandered lonely as a cloud
that drifts
3 i wandered lonely as a cloud that drifts i wondered lonely as a
clewd
4 i wandered lonely as a cloud that drifts i wandered wandered as a
cloud that drifts
5 a test of spaces a test of spaces what
For my purpose I used a finite state approach in a character by
character loop. V inefficient. The resulting lengthy macro follows my
sig.
To use select the cells in a column. It compares the cells immediately
to the right and marks *both*, synchronising on spaces.
Of course the full monty, synchronising when there are sufficiently long
correct strings would be the equivalent of using ExamDiff and I believe
that to be quite a hard problem.
BTW the "maxloop" in the code is because I am unable (MSW7HP + Excel
2010)to stop screaming or indeed any loops using pause/break, so I build
this into every loop.
HTH
JJ
'***********************************************************
' Purpose: compares selected column with its neighbour
' to the right and hilights differences.
'
'***********************************************************
Sub compSelection()
Dim rngC As Range
Dim i As Integer, j As Integer
Dim st As Integer ' state no
Dim mxi As Integer, mxj As Integer
Dim var1 As Variant
Dim var2 As Variant
Dim maxloop As Integer
For Each rngC In Selection
var1 = rngC.Text
var2 = rngC.Offset(, 1).Text
i = 1 ' index to var1
j = 1 ' index to var2
st = 0
mxi = Len(var1)
mxj = Len(var2)
maxloop = 10000
Do
maxloop = maxloop - 1
If (i > mxi) And (j > mxj) Then
st = -1
Else
If (i > mxi) Then
st = 5
End If
If (j > mxj) Then
st = 4
End If
End If
Select Case st
Case 0: ' loop while strings are identical
If Mid(var1, i, 1) = Mid(var2, j, 1) Then
If Mid(var1, i, 1) = " " Then st = 1 ' both spaces
i = i + 1
j = j + 1
Else
st = 2
End If
Case 1: ' synchronising on nonspace part 1
If Mid(var1, i, 1) <> " " Then
st = 10
Else
i = i + 1
End If
Case 10: ' synchronising on nonspace part 2
If Mid(var2, j, 1) <> " " Then
st = 0
Else
j = j + 1
End If
Case 2: ' hilighting string 1 to next space
If Mid(var1, i, 1) = " " Then
st = 3
Else
rngC.Characters(i, 1).Font.ColorIndex = 3
i = i + 1
End If
Case 3: ' hilighting string 2 to next space
If Mid(var2, j, 1) = " " Then
st = 1
Else
rngC.Offset(, 1).Characters(j, 1).Font.ColorIndex = 3
j = j + 1
End If
Case 4: ' hilighting string 1 to end
rngC.Characters(i, 1).Font.ColorIndex = 3
i = i + 1
Case 5: ' hilighting string 2 to end
rngC.Offset(, 1).Characters(j, 1).Font.ColorIndex = 3
j = j + 1
End Select
Loop While (st <> -1) And (maxloop > 0)
Next
End Sub