K
kabimeister
Hi
I have two Macros:
The fisrt compares two strings in Column B (Entry) and C (Corrected),
returns the string in column B to Column D (Highlight) and highlights
in blue the characters in column B that are different to those in
column C (Code and example follow):
Sub comp()
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
ID Entry Corrected Difference
1 IDAMA OBAMA IDAMA
2 6IMD 61MD 6IMD
3 9999ZM36 9999ZM35 9999ZM36
4 YYS3WDE YYS3WOE YYS3WDE
The second macro returns to column E (Difference) the highlighted
characters in the string in column D (Highlight) again code and
example below:
Sub Diff()
'
RowCount = 1
Do While Range("B" & RowCount) <> ""
If Range("B" & RowCount) <> Range("C" & RowCount) Then
CompareStr = “”
For i = 1 To Len(Range("D" & RowCount))
If Mid(Range("B" & RowCount), i, 1) <> _
Mid(Range("C" & RowCount), i, 1) Then
CompareStr = CompareStr & Mid(Range("B" & RowCount), i, 1)
End If
Next i
Range("E" & RowCount) = CompareStr
End If
RowCount = RowCount + 1
Loop
End Sub
ID Entry Corrected Highlight Difference
1 IDAMA OBAMA IDAMA ID
2 6IMD 61MD 6IMD I
3 9999ZM36 9999ZM35 9999ZM36 6
4 YYS3WDE YYS3WOE YYS3WDE D
I want to combine these two macros so they run as a single macro and
also return the postitions of the characters that are differrent to
Column F, for example:
ID Entry Corrected Highlight Difference Position
1 IDAMA OBAMA IDAMA ID 1,2
2 6IMD 61MD 6IMD I 2
3 9999ZM36 9999ZM35 9999ZM36 6 8
4 YYS3WDE YYS3WOE YYS3WDE D 6
Any help would be much appreciated.
Thanks.
I have two Macros:
The fisrt compares two strings in Column B (Entry) and C (Corrected),
returns the string in column B to Column D (Highlight) and highlights
in blue the characters in column B that are different to those in
column C (Code and example follow):
Sub comp()
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
ID Entry Corrected Difference
1 IDAMA OBAMA IDAMA
2 6IMD 61MD 6IMD
3 9999ZM36 9999ZM35 9999ZM36
4 YYS3WDE YYS3WOE YYS3WDE
The second macro returns to column E (Difference) the highlighted
characters in the string in column D (Highlight) again code and
example below:
Sub Diff()
'
RowCount = 1
Do While Range("B" & RowCount) <> ""
If Range("B" & RowCount) <> Range("C" & RowCount) Then
CompareStr = “”
For i = 1 To Len(Range("D" & RowCount))
If Mid(Range("B" & RowCount), i, 1) <> _
Mid(Range("C" & RowCount), i, 1) Then
CompareStr = CompareStr & Mid(Range("B" & RowCount), i, 1)
End If
Next i
Range("E" & RowCount) = CompareStr
End If
RowCount = RowCount + 1
Loop
End Sub
ID Entry Corrected Highlight Difference
1 IDAMA OBAMA IDAMA ID
2 6IMD 61MD 6IMD I
3 9999ZM36 9999ZM35 9999ZM36 6
4 YYS3WDE YYS3WOE YYS3WDE D
I want to combine these two macros so they run as a single macro and
also return the postitions of the characters that are differrent to
Column F, for example:
ID Entry Corrected Highlight Difference Position
1 IDAMA OBAMA IDAMA ID 1,2
2 6IMD 61MD 6IMD I 2
3 9999ZM36 9999ZM35 9999ZM36 6 8
4 YYS3WDE YYS3WOE YYS3WDE D 6
Any help would be much appreciated.
Thanks.