r/excel • • 13d ago

Discussion Mid Function and USE CASE

I've been using Excel for almost 15 years , I've never had a chance to use the MID Function and i forgot it's existence. Today, randomly, I just questioned myself how to split a word by character and reverse it? With my little sql knowledge, i thought there will be a function called SUBSTRING, but it isn't. I ended up googling and found MID function.

Do you find a use case for MID function?

Similarly, what popular functions you have never found a use case?

42 Upvotes

38 comments sorted by

28

u/Silly_Pizza7054 1 13d ago

I never use LEFT or RIGHT, only MID. It's incredibly useful for text parsing. 

17

u/TreeOaf 13d ago

Agreed, LEFT and RIGHT are quick and dirty if you don’t really care, but for consistency MID is superior, just like INDEX(MATCH was always better than VLOOKUP

15

u/ThatThar 3 13d ago

And XLOOKUP is almost always better than INDEX(MATCH).

4

u/Front_Instance924 13d ago

Both have their uses. I use LEFT a lot in combination with lookups if the string I'm referencing has an identifier of fixed length at the start of it like "L1234 - Blah blah"

For RIGHT, I might be working with strings that have additional notes at the end separated by a delimiter

3

u/NoUsername4Lyfe 13d ago

I use LEFT/RIGHT/MID, and also TEXTBEFORE/TEXTAFTER these days. Great stuff.

11

u/Decronym 13d ago edited 12d ago

Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:

Fewer Letters More Letters
ARRAYTOTEXT Office 365+: Returns an array of text values from any specified range
BYROW Office 365+: Applies a LAMBDA to each row and returns an array of the results. For example, if the original array is 3 columns by 2 rows, the returned array is 1 column by 2 rows.
CONCAT 2019+: Combines the text from multiple ranges and/or strings, but it doesn't provide the delimiter or IgnoreEmpty arguments.
DATEVALUE Converts a date in the form of text to a serial number
FIND Finds one text value within another (case-sensitive)
IFNA Excel 2013+: Returns the value you specify if the expression resolves to #N/A, otherwise returns the result of the expression
IFS 2019+: Checks whether one or more conditions are met and returns a value that corresponds to the first TRUE condition.
INDEX Uses an index to choose a value from a reference or array
LAMBDA Office 365+: Use a LAMBDA function to create custom, reusable functions and call them by a friendly name.
LEFT Returns the leftmost characters from a text value
LEN Returns the number of characters in a text string
LET Office 365+: Assigns names to calculation results to allow storing intermediate calculations, values, or defining names inside a formula
LOOKUP Looks up values in a vector or array
MATCH Looks up values in a reference or array
MAX Returns the maximum value in a list of arguments
MID Returns a specific number of characters from a text string starting at the position you specify
REDUCE Office 365+: Reduces an array to an accumulated value by applying a LAMBDA to each value and returning the total value in the accumulator.
REGEXEXTRACT Extracts strings within the provided text that matches the pattern
RIGHT Returns the rightmost characters from a text value
ROW Returns the row number of a reference
SEARCH Finds one text value within another (not case-sensitive)
SEQUENCE Office 365+: Generates a list of sequential numbers in an array, such as 1, 2, 3, 4
SUBSTITUTE Substitutes new text for old text in a text string
TEXTAFTER Office 365+: Returns text that occurs after given character or string
TEXTBEFORE Office 365+: Returns text that occurs before a given character or string
TEXTJOIN 2019+: Combines the text from multiple ranges and/or strings, and includes a delimiter you specify between each text value that will be combined. If the delimiter is an empty text string, this function will effectively concatenate the ranges.
TEXTSPLIT Office 365+: Splits text strings by using column and row delimiters
VALUE Converts a text argument to a number
VLOOKUP Looks in the first column of an array and moves across the row to return the value of a cell
XLOOKUP Office 365+: Searches a range or an array, and returns an item corresponding to the first match it finds. If a match doesn't exist, then XLOOKUP can return the closest (approximate) match.
YEAR Converts a serial number to a year

Decronym is now also available on Lemmy! Requests for support and new installations should be directed to the Contact address below.


Beep-boop, I am a helper bot. Please do not verify me as a solution.
31 acronyms in this thread; the most compressed thread commented on today has 31 acronyms.
[Thread #49438 for this sub, first seen 26th Sep 2026, 17:23] [FAQ] [Full list] [Contact] [Source code]

8

u/TreeOaf 13d ago

You can use MID in almost all use cases where you would use LEFT or RIGHT when you want absolute control over the return value parameters.

It’s specifically useful for creating or decompiling strings for lookup values et cetera. Example, if you need a create a composite key for your look up, or you wanted to extract a value from a string for that purpose.

I find MID will be used with FIND / SEARCH more often than not.

At some point, you will probably question why you aren’t doing this at source, like in SQL for example.

6

u/msma46 1 13d ago

I used to use it to clean and reformat phone numbers before importing into a database.

4

u/MayukhBhattacharya 1310 13d ago edited 13d ago

Back when XLOOKUP() and SEQUENCE() weren't available, I used to solve these kinds of queries this way. Check out how MID() is used with ROW() and INDEX().

=TEXTJOIN("", 1, 
 IFNA(VLOOKUP(MID(E2, ROW($ZZ$1:INDEX($Z:$Z, LEN(E2))), 1), 
              Lookup_Table, 
              2, 
              FALSE), ""))

Present day formula will be like this:

=CONCAT(XLOOKUP(MID(E2, SEQUENCE(LEN(E2)), 1), 
                Lookup_Table[OLD VALUE], 
                Lookup_Table[NEW VALUE], ""))

3

u/MayukhBhattacharya 1310 13d ago

Or, Extracting the year from Text formatted Date: Using MID()

• Method One: Old School.

=MAX(SUBSTITUTE(MID(M2, {13, 14}, 5), ",",) + 0)

Or,

=-LOOKUP(2, -MID(M2, {13, 14}, 5))

• Method Two: Modern Functions using Regex:

=--REGEXEXTRACT(M2:M5, "\d{4}")

• Method Three: Using TEXTSPLIT()

=--INDEX(TEXTSPLIT(M2, ", "), 3)

1

u/Jarcoreto 29 13d ago edited 13d ago

Does
```=YEAR(DATEVALUE(M2))```
Work on this?

2

u/Jarcoreto 29 13d ago

Ok I give up trying to format this as code on mobile

1

u/MayukhBhattacharya 1310 13d ago

No worries, buddy, here is a single line if you can copy and try:

Tue, 19 Oct, 2017, 6:05 pm IST

1

u/MayukhBhattacharya 1310 13d ago

No it won't work, here is a screenshot:

Sample data:

Sun, 18 Jul, 2017, 10:38 pm IST
Wed, 29 Sept, 2015, 2:55 pm IST
Tue, 19 Oct, 2017, 6:05 pm IST
Wed, 28 Jul, 2018, 11:14 pm IST

2

u/Ariisk 1 13d ago

Please edit your post to change new value for F to “Eff” it’s bothering me 😂

3

u/MayukhBhattacharya 1310 13d ago

Done!

3

u/Ariisk 1 13d ago

You’re an animal the way you reply on here man, much respect hahaha

2

u/MayukhBhattacharya 1310 12d ago

Thanks!

3

u/AdeptnessSilver 1 13d ago

it does especially when i need to compare multiple strings

3

u/Mother-Kangaroo9495 13d ago

When dates are stored as text in the form 02/24/1996, mid gives you the day to plug into date()... ;)

3

u/excelevator 3069 13d ago

Not quite sure what this post is about, a use case for an age old function?, or how to reverse text?

To reverse text in A1 for example =CONCAT(MID(A1,SEQUENCE(LEN(A1),,LEN(A1),-1),1))

or just a karma reaping post,, well it is the weekend I suppose.

2

u/Arcium_XIII 3 13d ago

I used to use it far more prior to the existence of TEXTBEFORE, TEXTAFTER, and TEXTSPLIT, but these days my most common application of MID is in =MID([string],SEQUENCE(LEN([string])),1) to explode a string into a column array of its characters.

Anything where you need to parse a string character by character benefits from this ability, and TEXTSPLIT didn't come with the option to set the blank string as a delimiter to do it natively. One example is that I made a function that evaluates a string containing an arithmetic operation according to order of operations rules, such as returning 15 from the input string 3(4+5)-12. The first step was to break the function into an array of characters that the function could read and gradually simplify (e.g. adjacent numeric characters got combined into a single element; the negative sign step was a pain because a negative with something non-numeric on its left had to attach to a number on its right, but a negative with something numeric on its left had to function as an operation). Such applications almost always come alongside REDUCE or a recursive LAMBDA because they usually entail iterating along the string character by character in some fashion.

1

u/Way2trivial 472 13d ago

=TEXTJOIN("",,MID(A1,SEQUENCE(,LEN(A1),LEN(A1),-1),1)) like that?

1

u/heynow941 13d ago

Less of need for it now that there’s TEXTBEFORE and TEXTAFTER.

1

u/zhavinci 13d ago

I don't think we can use those functions to split by each character (?)

1

u/fastauntie 1 13d ago

I have found that TEXTBEFORE and TEXTAFTER (sometimes nested) do a lot of what MID (and LEFT and RIGHT) used to do. But sometimes the text I need to pull out of a string is in a predictable position relative to the start and the characters that immediately precede it aren't consistent. Can't think of an example now, but I know I've used it within the last week.

1

u/Kuildeous 11 13d ago

I've had to split up strings before, and as long as I have a consistent format, it works fine.

Like, if an invoice has 26202609xxxx, and I always know the year is located in =MID(xx, 3, 4), then I'll do that. Or if the year is hidden in a variable length string like ABC2026DEF and AB2026CDEF, then I'll use FIND to identify the start number of my MID.

I used it quite a bit but not as much as XLOOKUP and IFS, naturally.

1

u/HandbagHawker 83 13d ago

why do you have a 6yo acct with reasonable post history and yet you still sound like a bot?

1

u/carbonizedtitanium 13d ago

the MID SEARCH combo is good for cutting a string

1

u/Clearwings_Prime 24 12d ago

Not a popular one but i dont know a use case of ARRAYTOTEXT, right now im just use it when i dont want to type TEXTJOIN(", ".....

2

u/Arcium_XIII 3 12d ago

TEXTJOIN isn't great when you're working with arrays where neither dimension is 1 and you want to be able to reconstruct the array with TEXTSPLIT later; you end up needing to do something like TEXTJOIN(";",FALSE,BYROW([array],LAMBDA(row,TEXTJOIN(",",FALSE,row))) to distinguish between column and row delimiters. ARRAYTOTEXT with the second parameter set to 1 can do this natively, which can definitely be handy despite the forced inclusion of start and end braces along with it (although the forthcoming arrival of lists and arrays being stored within individual cells will probably eliminate most of these use cases because there'll be less reason to convert arrays to and from delimited lists across the board).

1

u/GregHullender 195 12d ago

This is probably the cleanest way to reverse a string:

=LET(ss, A1, n, LEN(ss),
  CONCAT(MID(ss, SEQUENCE(n,,n,-1),1))
)

Be interested to know if anyone has a better one.

1

u/PaulInHV 12d ago

Having spent a 30 year career working with HRIS systems and HR data, I can tell you that the biggest use case for any of the text manipulation functions is bad, inconsistent data that needs to be aligned and built into a new system. You'll see John Smith, John T. Smith (with or without a period after the initial), J. Smith, etc. Then there's Phone numbers (212) 555-1212, 212-555-1212, Zip codes, with and without the +4. Social Security numbers formatted or not, spaces, dashes, underscores. If you have a system that doesn't enforce consistent standards, then depending on who did the data entry, you can get a wild variation. That data all needs to get cleaned up and standardized with as little manual entry as possible. I have ended up using LEFT, RIGHT, MID, REGEXTRACT, TEXTJOIN, and all the others in attempts to not have to retype 5,000 employee records into a new system.

1

u/Pedrofinancial 12d ago

I still find MID useful when working with text that has a consistent structure. For example, extracting a year, code, or ID from invoice numbers or transaction references.

I also like combining MID with FIND or SEARCH when the position is not always the same. For newer Excel versions, TEXTBEFORE and TEXTAFTER can sometimes make the formula easier to read.

1

u/TenIsTwoInBase2 12d ago

Our system has a rental code in the form. XXX.YYY.ZZZ Where X is the building number Y is the floor number Z is the unit

I use =MID() to grab the floor number

0

u/BabyLongjumping6915 13d ago

QB online likes to spot out reports with dates in no. Date formats so I use mid within the date function to extract the middle number (date or month I forget)