Link to home
Start Free TrialLog in
Avatar of jana
janaFlag for United States of America

asked on

Function or formula to identify the last repeated character in a cell in Excell

We have a list of files in an excel and want to separate their file extension.  We are using a combination of commands like search(), len(), left(), right().  However some files has various periods in their name (for example, file.of.mine.txt), thus making it difficult to set the 3 character of the extension.  So we thought if we can identify the last period we can calculate the exact 3 or 2 or 5 extension that a file may have (for example, filename.text or filename.manifext).

please advice.
Avatar of aikimark
aikimark
Flag of United States of America image

You can use instrrev() to find the last instance of a char/string within a target string.
Example:
strFilename = "file.of.mine.txt"
strBasename = Left(strFilename, Instrrev(strFilename, ".") -1)
strExtension = Mid(strFilename, Instrrev(strFilename, ".") +1)

Open in new window


Note: You can also get this information with a FileSystemObject
strExtension = Split("file.of.mine.txt", ".")(UBound(Split("file.of.mine.txt", ".")))
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jana

ASKER

The formula worked excellently separating the extension, but how do modify the formula to identify the last repeated period (".")?
I don't understand. What do you mean by "identify"?
Avatar of jana

ASKER

example,

in file.of.mine.txt, the last "." is in the 13 position.  We want to identify the last ".".
@rayluvs

Have you tested the other comments?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jana

ASKER

The other comments don't work in the cell, we want work directly on Excel cell.

Thanx Rg worked!