View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
SpiderBoy SpiderBoy is offline
external usenet poster
 
Posts: 1
Default Comparing two arrays/ranges

Hi there guys!
I have two tables with data say:

Cancun Merida
Article1 50.00 40.00
Article2 60.00 70.00

And the other table:

Cancun Merida
Article1 500.00 4000.00
Article2 600.00 7000.00

i need to compare the data in both tables, and color code the first one,
because we have two different prices, and the second table "normally" is the
first one by 6 (50.00 * 6) , but because the rates change depending on
season and customer, sometimes this "by 6" rule does not apply. So i need to
chage the color in the cells where the rule is not valid.
What im triying here is:

Sub CompararValores()
'varible declarations
Dim selec1, selec2 As Object
Dim i, j, numrows, numcols As Integer
Set selec1 = Application.InputBox(prompt:="Selecciona el Rango 1",
Type:=8)
Set selec2 = Application.InputBox(prompt:="Selecciona el Rango 2",
Type:=8)
i = CInt(selec1.Rows.Count)
numrows = CInt(selec2.Rows.Count)
j = CInt(selec1.Columns.Count)
numcols = CInt(selec2.Columns.Count)
If (numrows = i) And (numcols = j) Then 'To see if the selections are or
the same size

'THE PROBLEM is in this piece of code because i dont know how to cycle
trough the values of a range
'and i can't compare cell to cell (i.e. A1 with D1)

For Each j In selec1.Columns 'Here is the problem
If CInt(j.Value) = CInt(selec2.Offset(1, j).Value) Then
'Change color of cells
End If
Next j
Else
MsgBox "Selecciona rangos del mismo tamaņo", vbExclamation
End If
End Sub

I could of course use two FOR cycles to compare each cell in the first range
with each cell of the second range, of couse this is not as ellegant as the
solution i want.

Any help or pointer to a help page would be apreciated