vb simple formula

  • Thread starter Thread starter Cesar Zapata
  • Start date Start date
C

Cesar Zapata

Hi,

is seems simple but I cant get it to work.


this is what I'm trying to do in a module.



dim cell as range

for each cell in range ("a2:a200")


if cell.value = any cell on the second sheet range (b1 to b50 ) then


do whatever



next cell.



what is the right code to check if the current cell value is equal to any
cell in the second sheet range b1 to b50?


Thanks for your help.
 
dim cell as range

for each cell in range ("a2:a200")
if application.countif(Range("B1:B50"),cell.value) > 0 then
msgbox cell.Address & " Matches a value"
end if
Next

If you want to find which cell, you can use

Dim res as Variant


res = Application.Match(cell.Value,Range("B1:B50"),0)
if not iserror(res) then
msgbox cell.Address & " matches value in " & Range("B1:B50")(res).Address
End if

Regards,
Tom Ogilvy
 
try

Sub IfCellMatch()
On Error Resume Next
For Each c In [a2:a14]
x = Sheets("data").Range("b1:b21").Find(c)
If c = x Then MsgBox c
Next
End Sub
 
Back
Top