match cell to range

N

Nigel

Set rng = Range("H5:H200")
For Each c In rng
If c.Value = Range("X9").Value Then
FoundRow = c.Row
Range("F" & FoundRow).Value = Range("V8").Value
Exit For
End If
Next c


so i am trying to look for the value of X9 in the range h5:h200
when i find the match...i wanted to take the value of column F in the
same row as the found match, and set V8 to the same value.....
i have a feeling its not even running through the if then statement
tho....but im not sure.....
whats wrong? thx
 
N

Nigel

should this
Range("F" & FoundRow).Value = Range("V8").Value

read
Range("V8").Value = Range("F" & FoundRow).Value
 
N

Nigel

well i finally figured out how to use the step into feature, and found
that the script never makes it past the If Then Statement....it goes
from If Then.....to End If, to Next....it never runs the code between
the If Then and End If lines
 
M

michael.beckinsale

Nigel,

I have tested this and it works. You must, obviously, have something in
column F of the c.Row for V8 to be populated.

Dim LoopRange
Set rng = Range("H5:H200")
For Each c In rng
If c.Value = Range("X9").Value Then
FoundRow = c.Row
Range("V8").Value = Range("F" & FoundRow).Value
Exit For
End If
Next c
End Sub

Regards

Michael Beckinsale
 
B

Bob Phillips

Another way

On Error Resume Next
iRow = Application.Match(Range("X9").Value,Range("H5:H200"),0)
On Error Goto 0
If iRow > 0 Then
Range("V8").Value = Range("H5:H200").Offset(iRow-1,-2).Value
Else
MsgBox "Not found"
End If

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Index and Match - Errors 6
find TWO values in a worksheet 3
Inaccurate count with code 6
Copy code failing 2
Code condition 3
Conflict 8
.Find, cells with spaces 2
A simple if <> nn then Msgbox "No Match" 5

Top