RJB
RJB

Reputation: 669

Conditionally rename cells in Excel

I have an Excel spreadsheet of 5000 rows. One of those rows contains image names. The format of these image names varies but what I want to do is check to see if that image name contains the string 'front' and begins with 'alt-'. If it does, I want to change the prefix from "alt-" to "main-". Is this possible?

So for example:

alt-brand-product-name-colour-front.jpg  << Rename "alt-" to "main-"
alt-brand-product-name-diffcolour-front.jpg  << Rename "alt-" to "main-"
alt-brand-product-name-colour-back.jpg
alt-brand-product-name-colour-side.jpg
alt-brand-product-name-reallylongcolour-front.jpg  << Rename "alt-" to "main-"

Any help massively appreciated :-)

Upvotes: 1

Views: 4590

Answers (1)

Phil Applegate
Phil Applegate

Reputation: 567

You will probably want to use the formula below. If "front" is found then it will replace all occurances of "alt" with "main". If "front" is not found then the original string will be left as it is. Cell A1 represents your original filename.

=IF(ISERR(FIND("front",A1)),A1,SUBSTITUTE(A1,"alt","main"))

Upvotes: 2

Related Questions