In Excel 2010, I am trying to get this small script to work.
If searchVal = findVal Then
Set rngX = Worksheets("NEW Format").Range("C:C").Find(What:=resultVal, LookIn:=xlValues)
ID = rngX.Offset(0, -1).Value
End If
I know the 'searchVal' is correct, I know the 'findVal' is correct, and I know the 'resultVal' is correct. Also, rngX is defined as a range. However, each time this runs, the rngX is always Nothing. The ID should be set as the row where 'resultVal' is found, one cell to the left.
I tried it a different way and the oucome was exactly the same.
On Error Resume Next
If searchVal = findVal Then
Set rngFindValue = ActiveSheet.Range("C1:C100").Find(What:=resultVal, After:=ActiveSheet.Range("C1"), LookIn:=xlFormulas)
ID = rngFindValue.Address
ID = rngFindValue.Offset(0,-1)
End If
I looked at the link below and none of those samples work for me.
I must be missing something really simple here, but I don't know what it is!
Editing my OP: I tried this as well.
If searchVal = findVal Then
Range("C2:C" & LRow).Select
For Each cell In Selection
If cell = resultVal Then
ID = cell.Offset(0, -1).Value
End If
Next
End If
In the Immediate Window I can see that cell = resultVal. I still don't understand why this is not working.
I just found something interesting. The two variables seem to be different when I examine them in the Watch Window.
It looks like there is a trailing space after the second variable, even though I put a TRIM() around it. When I look at both variables in the Immediate Window, both appear to be exactly the same. Maybe the issue is due to the data type...not sure...