2018-01-25

Excel: last character/string match in a string

Đôi khi có nhu cầu phải tìm ký tự hay sub-string cuối cùng xuất hiện trong Excel.
Search thì cũng ra nhanh nhưng mình note lại đây tập trung 1 chỗ.

Ví dụ
https://stackoverflow.com/questions/18617349/excel-last-character-string-match-in-a-string
https://www.excel-university.com/find-the-last-occurrence-of-a-delimiter-to-retrieve-the-lowest-sub-account-from-quickbooks-in-excel/

=FIND("@",SUBSTITUTE(A1,"\","@",(LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))/LEN("\")))

Mình dùng công thức này, ví dụ tìm "\" cuối cùng của cell A1

=SEARCH("@",SUBSTITUTE(A1,"\","@",LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))))