jonathynblythe
New Member
- Joined
- Apr 14, 2011
- Messages
- 4
Hello again...
Here's a code I have that I use for comparing two sheets in an excel workbook
I have another code from Bob Phillips over at excelguru.ca and he gave me this:
This code unfortunately doesn't work without giving me syntax errors, however it does what I want when I'm able to bypass the error - it highlights ONLY the text portions within a given cell rather than highlighting the whole cell.
What I was wondering was... how would I combine these two codes into one? Meaning, instead of the red highlights for the whole cell, how do I make SHG's code do the text highlighting (as indicated by Bob's code above) rathen than the cell itself?
Thanks in advance!
JB
Here's a code I have that I use for comparing two sheets in an excel workbook
Code:
Sub FindMismatch()
Dim rInp As Range ' input range
Dim cellI As Range ' cell in rInp
Dim r2F As Range ' Sheet2 col F
Dim cellF As Range ' cell in col F
Dim vi As Variant ' for/each variable
Set rInp = Application.InputBox("Choose the first range", "Range 1", Type:=8)
If rInp Is Nothing Then Exit Sub
With Worksheets("Sheet2")
Set r2F = .Range("F1", .Cells(.Rows.Count, "F").End(xlUp))
End With
For Each cellI In rInp
Select Case WorksheetFunction.CountIf(r2F, "*" & cellI.Text & "*")
Case 0
cellI.Interior.ColorIndex = 5
Case 1
For Each vi In Array(-5, -4, -3, -2, -1, 1)
For Each cellF In r2F
If cellF.Value = cellI.Value And cellF.Offset(0, vi).Value <> cellI.Offset(0, vi).Value Then
cellI.Offset(0, vi).Interior.ColorIndex = 3
End If
Next cellF
Next vi
End Select
Next cellI
End Sub
I have another code from Bob Phillips over at excelguru.ca and he gave me this:
Code:
Public Sub ProcessData()
Dim cell As Range
Dim Lastrow As Long
Dim i As Long, j As Long
Application.ScreenUpdating = False
With Worksheets(1)
Lastrow = .UsedRange.Rows.Count + .UsedRange.Cells(1, 1).Row - 1
For i = 1 To Lastrow
On Error Resume Next
Set cell = Worksheets(2).Columns(1).Find(.Cells(i, "A").Value2)
On Error GoTo 0
If Not cell Is Nothing Then
Call CheckValues(Worksheets(1), i, 2, cell)
Call CheckValues(Worksheets(1), i, 3, cell)
Call CheckValues(Worksheets(1), i, 4, cell)
Call CheckValues(Worksheets(1), i, 5, cell)
Call CheckValues(Worksheets(1), i, 6, cell)
End If
Next i
End With
Application.ScreenUpdating = True
End Sub
Private Function CheckValues( _
ByRef sh As Worksheet, _
ByVal ThisRow As Long, _
ByVal ThisCol As Long, _
ByRef MatchCell As Range)
Dim vecElements As Variant
Dim vecElements2 As Variant
Dim i As Long
With sh.Cells(ThisRow, ThisCol)
If .Value2 <> MatchCell.Offset(0, ThisCol - 1).Value2 Then
vecElements = Split(.Value2, " ")
vecElements2 = Split(MatchCell.Offset(0, ThisCol - 1).Value2, " ")
For i = LBound(vecElements) To UBound(vecElements2)
If vecElements(i) <> vecElements2(i) Then
.Characters(Application.Find(vecElements(i), .Value2), Len(vecElements(i))).Font.ColorIndex = 3
End If
Next i
End If
End With
End Function
This code unfortunately doesn't work without giving me syntax errors, however it does what I want when I'm able to bypass the error - it highlights ONLY the text portions within a given cell rather than highlighting the whole cell.
What I was wondering was... how would I combine these two codes into one? Meaning, instead of the red highlights for the whole cell, how do I make SHG's code do the text highlighting (as indicated by Bob's code above) rathen than the cell itself?
Thanks in advance!
JB