Using INDIRECT along with Text-string functions

BlackieHamel

Board Regular
Joined
May 9, 2014
Messages
93
I'd like to use text string functions to retrieve 3 letters from the middle of a word, measured from x spaces in. For example, if my string is UNITEDSTATESOFAMERICA in A1, and I want to begin 5 spaces in, I can use


=MID(A1,5,3) and it returns EDS
But if I want to do this 5 spaces in from the right, my formula is
=LEFT(RIGHT(A1,5),3) and it returns ERI


This works for me. But I'd also like to be able to change this on the fly, and I think I need to use the INDIRECT function, so if a cell, say, E1 is "L" it would do the MID function and if E1 is "R" it would do the LEFT and RIGHT functions.


I despair of figuring out where the apostrophes and quote marks would go in such a statement. Can someone help?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi

Welcome to MrExcel forum.

Despair no longer, try this :-
Code:
=MID(A1,IF(E1="L",5,LEN(A1)-4),3)

hth
 
Upvote 0
Thanks so much! Exactly what I needed -- and no INDIRECT needed! Sometimes you do need an IF statement....

Thanks for the feedback.

Pleased to have helped solve your problem.

Good luck with your project.

And just for the record you can do it without an IF :-
Code:
=MID(A1,5+(E1="R")*(LEN(A1)-9),3)

hth
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,578
Messages
6,125,642
Members
449,245
Latest member
PatrickL

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top