View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
onedaywhen onedaywhen is offline
external usenet poster
 
Posts: 459
Default Array Problem, Help Please.

If your comparison values follow a pattern (your example, letters A-E), exploit it:

Option Explicit

Sub tester_1()
Dim cell As Range
Dim i As Integer
For Each cell In Range("a1:a3")
i = Asc(cell.Value)
If i = Asc("A") And i <= Asc("E") Then
cell.Interior.ColorIndex = 4
MsgBox " Match in " & cell.Address & vbNewLine & _
cell.Value & " = " & cell.Value
End If
Next cell
End Sub

(Bubu) wrote in message . com...
the following macro has to compare, cell by cell, in a
certain range, the cell value with a list of values,
but it is not working properly because
it seem there is a match in all three cells, but
the match is only in Range(A2), because "C" = "C"

Where is the problem ???

Thanks for Your suggestion.

Robert.


example

' A
---'----------------
1 ' t
--------------------
2 ' C
--------------------
3 ' 7
--------------------


Sub tester_1()
Dim cell As Range
For Each cell In Range("a1:a3")
Dim i As Integer
Dim x As Variant
x = Array("A", "B", "C", "D", "E")
For i = -1 To 4
On Error Resume Next
MsgBox x(i)
If cell.Value = x(i) Then
cell.Interior.ColorIndex = 4
MsgBox " Match in " & cell.Address & vbNewLine & cell.Value & " = " & x(i)
End If
Next i
Next cell
End Sub