I have an array of names stored in column a in Sheet 2. Say John, Smith, Bob, Peter, William. I need to check a cell in Sheet 1 and see what name is comes last in that cell.
Suppose the content in Sheet1, A1 is "William came home early. Smith rang the bel and Bob opened the door to see if that was Peter". In this, my requirement are, which all names contained in this sentence in A1 cell and whose name came last in this. Obviously it's Peter and I need it to be returned using vba.
I have written a macro using InStrRev function and using MyNames array which contains the names. However it searches the name in array in descending order only.
InStrRev(Range("t" & r).Value, MyNames(t), -1, vbTextCompare)