View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.newusers
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default Compare and Highlight Rows

Except that your solution is less efficient, non-automatic, and will not
work for users who disable macros.

Given your original problem statement, it seems to me a real
disadvantage that you rely on the inspectionID column on Worksheets(1)
being selected rather than specifying it in your macro.

Your macro also doesn't meet your criterion of "highlight(ing) those
matches on each worksheet", as it will only highlight the rows on sheet
1.

As a great programmer, you might also recognize that using variants is
rather inefficient compared to using range objects or simple data types.
And one should generally avoid using the Integer data type for rows,
since Integers are limited to +32,767 and the number of rows isn't.

And, finally, the VBA comparison is likely much less efficient than
using a built-in function, say:

Const idCol1 As Long = 1 'worksheet 1 ID column
Const idCol2 As Long = 2 'worksheet 2 ID column
Dim compareRange as Range
Dim rCell As Range

With Worksheets(2)
Set compareRange = .Range(.Cells(2, idCol2), _
.Cells(.Rows.Count, idCol2).End(xlUp).Row)
End With
With Worksheets(1)
For Each rCell in .Range(.Cells(2, idCol1), _
.Cells(.Rows.Count, idCol1).End(xlUp).Row)
With rCell
If Application.WorksheetFunction.CountIf( _
compareRange, .Value) 0 Then _
.EntireRow.Interior.ColorIndex = 6
End With
Next rCell
End With

In article ,
Lisab wrote:

Because I know there is always more then one way to skin a cat. That is what
makes me a great programmer. By the way, here is the solution.
------------------------------------
Dim compareRange As Variant
Dim x As Variant, y As Variant
Dim counter As Integer

Set compareRange = Worksheets(2).Range("A2:A149")
counter = 1

For Each x In Selection
For Each y In compareRange
If x = y Then Selection.Rows(counter).EntireRow.Interior.ColorIn dex
= 6
Next y
counter = counter + 1
Next x


"Peo Sjoblom" wrote:

Why swim the river to get to the water, you have been given a solution
using
conditional formatting?