Explanation
A MAC (Media Access Control) address is a unique identifier assigned to most network adapters. Two common IEEE 802 standards display a MAC address in 6 groups of 2 hexadecimal digits separated by a colon (:) or hyphen (-) like this:
"01-23-45-67-89-ab"
"01:23:45:67:89:ab"
To format a text string with 12 characters in the same way, you can use a formula like this:
=TEXTJOIN(C5,1,MID(B5,SEQUENCE(6,1,1,2),2))
Working from the inside out, the SEQUENCE function is used to generate an array of 6 numbers used as the start_num argument in the MID function:
SEQUENCE(6,1,1,2) // returns {1;3;5;7;9;11}
These are returned directly to the MID function :
MID(B5,{1;3;5;7;9;11},2)
With the text “112233445566” in B5, the MID function returns an array of 6 strings:
{"11";"22";"33";"44";"55";"66"}
This array is returned to the TEXTJOIN function as the text1 argument, and with the colon (:) as the delimiter from C5, we have:
=TEXTJOIN(";",1,{"11";"22";"33";"44";"55";"66"})
The TEXTJOIN function concatenates the 6 strings together using a colon, and returns a single string as a final result:
11:22:33:44:55:66
The formula in D6 works exactly the same, except it uses the hyphen in C6 to join the strings:
11-22-33-44-55-66
Three groups of four
Another standard format is 3 groups of 4 hexadecimal digits, separated with a dot. To create a MAC address in this format, use a formula like this:
=TEXTJOIN(".",1,MID(B5,SEQUENCE(3,1,1,4),4))
SEQUENCE now generates 3 start numbers incremented by 4 characters:
SEQUENCE(3,1,1,4) // returns {1;5;9}
And MID returns 3 strings:
{"1122";"3344";"5566"}
The TEXTJOIN function then concatenates these strings separated with a dot (.) character:
"1122.3344.5566"
Explanation
In this example, the goal is to make a noun plural when the number of items is greater than one. In many cases, a noun can be made plural by adding an “s”. However, many nouns have an irregular plural form, and the main challenge is to handle these exceptions.
Ingredients
In the example shown, the formula uses these ingredients:
- IF function – to check the number of items
- VLOOKUP function – to lookup irregular plural forms
- IFNA function – to take action when there is no irregular form
- Concatenation – to glue text together
Note: There are many ways to solve a problem like this in Excel, and this is just one approach.
Adding an “s”
In the simplest case, the only task is to add an “s” to the end of a word using concatenation . This can be done with a formula like this:
=C5&"s" // simple concatenation
The ampersand operator (&) is used to join an “s” to the word in column C.
However, we don’t want to add an “s” unless the number in column B is greater than 1. For this, we can use the IF function to check the number in column B:
=IF(B5>1,C5&"s"),C5)
In this version of the formula, we only add an “s” when the number in B5 is greater than 1. At this point, the formula handles the base case without trouble, but it won’t handle words with irregular plural forms.
Handling irregular forms
To handle words with an irregular plural form, we need to perform a lookup. In the example shown, we do this with the VLOOKUP function :
=VLOOKUP(C5,wordtable,2,0)
where wordtable is the named range F5:G11. Here, we use VLOOKUP to locate a word in a table and return the irregular plural from the second column. Obviously, this only works when the table contains an entry for a given word. If a word does not exist in the table, VLOOKUP will return a #N/A error, and we can use this error to take some other action. The trick is to nest VLOOKUP inside the IFNA function to trap the error like this:
=IFNA(VLOOKUP(C5,wordtable,2,0),other)
where “other” represents a different action. The idea is that words with an irregular plural form need to have an entry in the table. At this point in the formula, we know the word should be plural. If we check the table and can’t find the word, we can assume the word does not have an irregular plural form and we can simply add an “s”.
Putting it all together
We now have all the pieces we need for a single formula:
- Make plural only when number > 1
- Handle a regular plural form
- Handle an irregular plural form
We now need to assemble these pieces together in a logical flow like this:
If number is greater than one, make the word plural, otherwise, return the original word. When making a word plural, check a custom table first to see if there is an irregular form. If there is an irregular form, use it. If an entry is not found, simply add an “s”.
The formula that implements this logic looks like this:
IF(B5>1,IFNA(VLOOKUP(C5,wordtable,2,0),C5&"s"),C5)
The formula that appears in the example performs one additional step: it concatenates the number from column B to the result from the formula above so that the number appears together with the plural form of the noun:
=B5&" "&IF(B5>1,IFNA(VLOOKUP(C5,wordtable,2,0),C5&"s"),C5)
This results in a text string like “3 apples” and it makes it easier to quickly check results.
Note: if a noun has an irregular form but is not listed in the custom table, this formula will incorrectly add an “s”. Therefore, all words with an irregular plural form that you want to handle must exist in the custom table. This is a limitation of the formula.