I am trying to write a function which searches through a column and return the cell which contains the last match.
For example, if I have cell A5 as my active cell
A1 -> Text
A2 -> wefwqef
A3 -> Text
A4 -> eorbebr
I would want to search through the array for 'Text' and for it to return the cell A3 as that is the last match.
But if I have cell A7 as my active cell
A1 -> Text
A2 -> wefwqef
A3 -> Text
A4 -> eorbebr
A5 -> fhyeher
A6 -> Text
Then it would return A6 as my result.
I have been playing with the FIND function to try and get it to work, but I keep getting errors (Application or object based error).
My plan is to execute this code as part of a larger loop and in each case, it returns the value closest to the active cell. (I hope that makes sense)
This is the code I have so far:
Range("A19:I19").Select
'ActiveCell.FormulaR1C1 = Sheets("Sheet1").Cells(9, 5).Value & ":5 CTs,
O/C " & _
'Sheets("Sheet1").Cells(9, 8).Value * 100 & "% @ " & _
'Sheets("Sheet1").Cells(9, 9).Value & " TM"
Dim Rng As Range
With Sheets("Sheet1").Range(Cells(9, 3), Cells(Line, 3))
Set Rng = .Find(What:="Primary", _
After:=.Sheets("Sheet1").Cells(Line, 3), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)
I also imagine that when I can get this to work, I would include an DO or IF statement which would say, once value has been stored in Rng then cellx = rng.
Please help! What is wrong with this code??