Formulas: Using Built-In Functions Text Formulas
Formulas: Using Built-In Functions Text Formulas
Formulas: Using Built-In Functions Text Formulas
I have separated the formulas and VBA code into individual pages. This page is
only formulas.
Using Built-in Functions Text Formulas
• Nested IF statements -- note you are • Grab the last part of a string into a
limited to 7 nested IFs new formula
• Test for Multiple Conditions then • Extract and count the number of like
perform calculation (07/28/2001) elements in the middle of a string
• Using VLOOKUP instead of nested • A customer wanted to show both the
IFs formula and results in the same cell.
• Figure RANK but do not display a It’s not very smart or useful but it
rank above 10 works.
• Generate a RANDOM character • Build an Array function
• Convert Kilograms to Pounds and o Compare Array revisited
Ounces • Longest formula I ever created
• ROUNDing the result • Using MAX and MATCH; another
• Convert a number to Feet and Inches LOOKUP
(01/09/2002) o Another example of using MAX
and MATCH and INDIRECT
• Using external number templates in a
spreadsheet
• Change names from Last comma First
to separate pieces (03/30/2001)
Formulas
Page 1 of 7
=IF(U14>=10,6,IF(U14>8,5,IF(U14>5,4,IF(U14>3,3,IF(U14>=1,2,IF(U14<1,0))))))
-- Six nested IF statements is a little much. I later converted it to a custom Function.
If one has 10 or more years, 6 weeks vacation; more than 8, 5 weeks, etc..
Check this formula for converting Kilograms to Pounds and Ounces; be sure you
have been to Tools, Add-Ins and checked Analysis Toolpak.
=INT(CONVERT(A2,"kg","lbm"))&" lbs " &INT(
MOD(CONVERT(A2,"kg","ozm"),16))& " oz"
Similar formula as above but this one converts a number to Feet and Inches
=INT(CONVERT(A2,"ft","ft"))&" feet " &INT( MOD(CONVERT(A2,"ft","in"),12))&
" inches"
I am busily moving files to a new place and needed to show the disposition of the files
without typing everything again. Here is the solution, row 1 showing the formula and row 2
the finished product:
A B
="\\Occteccdr005\Archive\"& MID(A1,19,LEN(A1)-
1 L:\SHARE\STANDARD\3COM\3C589\INFO 19)
2 L:\SHARE\STANDARD\DOCUMENT \\Occteccdr005\Archive\DOCUMENT
I started with a list of 1,246 file directories. My mission was to analyze and determine the
final disposition of each one. The first problem was to find out what I had. I needed to
know how many sub-directories were under each major heading.
Here is a sample of the data:
L:\SHARE\STANDARD\DOCMNT
L:\SHARE\STANDARD\DOCUMENT
L:\SHARE\STANDARD\DOCUMENT\LNOTES
L:\SHARE\STANDARD\HP
L:\SHARE\STANDARD\HP\123R3X
L:\SHARE\STANDARD\HP\ADOBEW95
L:\SHARE\STANDARD\HP\COLORADO
L:\SHARE\STANDARD\HP\COLORADO\NT351
L:\SHARE\STANDARD\HP\COLORADO\NT351\FLOPPY
L:\SHARE\STANDARD\HP\COLORADO\NT351\T4000
I knew that the directory I wanted to start with began after STANDARD\ or the 19th
position. Here is the formula for counting the occurrences.
DOCMNT 1 {=SUM(IF(MID('Directories'!$A$2:$A$1246,19,LEN($A12))=$A12,1,0))}
Formulas
Page 2 of 7
DOCUMENT 2 {=SUM(IF(MID('Directories'!$A$2:$A$1139,19,LEN($A12))=$A13,1,0))}
HP 111 {=SUM(IF(MID('Directories'!$A$2:$A$1246,19,LEN($A12))=$A14,1,0))}
The solution is an array formula. SUM the numbers, IF in the string at Directories!A2
through A1139 (the sample above), beginning at position 19 and continuing for the length
of the thing in A12 which is DOCMNT with a length of 6; add 1 (one) to the total, else add 0
(zero). At the conclusion hold down the Ctrl, Shift, and Enter keys simultaneously to tell
Excel that it is an Array function.
Since I wrote this one, I have found more uses for it. I also found that I needed to extract
the sections to another file quickly. This was done in a VBA macro.
So, you want to figure out how many hours someone worked. I get several requests
each week from people doing something with time-cards. These are the best
examples I have. If they do not work, try somewhere else.
=SUM(A1:A25)/.04166667 or maybe =(A2-A1)/.04166667
.04166667 is the Excel serial number equivalent that represents one hour
=INT(SUM(A1:A25)/.04166667)&":" &MINUTE(MOD(SUM(A1:A25),1))
converts to integer text and looks like hours & minutes.
You already have the time, but you need to know the number of minutes. Cell A1
contains the elapsed time of 02:00, =A1*60/0.4166667 the answer is 120.
You have total minutes and you want to know how many hours and minutes
Assuming total minutes are in A1 =INT(A1/60)&" hours "&MOD(A1,60)& "
minutes"
get the integer of A1 divided by minutes in hour and remainder is minutes MOD
total after dividing by 60
128 equals 2 hours 8 minutes
Formulas
Page 3 of 7
40,0)
2 48 40 8
3
Round an involved formula so that the result is only 2 decimal places. My customer
had other calculations that were dependent on this number and the results looked
skewed.
Surround the formula with the =ROUND() statement:
=ROUND(((A1+B5)/C1),2) produces 2 decimal places.
Build an Array function. For example, you need to create an AVERAGE with an IF
statement. To exclude zeros (0) from the calculation, you might tell Excel what in an
array of number to exclude. After keying your formula, hold down the Control and
Shift keys while pressing Enter to complete the array. This causes brackets {} to
display around the formula.
{=AVERAGE(IF(C4:C50,C4:C5,""))} - If C4 through C5 do not have zeros, use
those cells, else use blank; then average the cells remaining.
Here is a formula for counting the number of items meeting a certain criteria:
=SUM(IF(A1:A17<=100,1,0))
=SUM(IF(A1:A16>100,IF(A1:A16<500,1,0)))
If less than or equal to 100, add 1, else add 0. The second uses 2 criteria to
determine first if the number is greater than 100 and then if it is less than 500. After
keying your formula, hold down the Control and Shift keys while pressing Enter to
complete the array. This causes brackets {} to display around the formula.
(04/15/2001)
Another Array formula where we count the number of cells where a date is in a
particular month.
{=SUM(IF(LEFT(TEXT(B3:B14,"mmddyy"),2)="12",1,0))} - Starting from
the middle, take the dates in B3 through B14 and convert to text in the format
mmddyy. Grab the left 2 characters (mm) and look for 12. If found add 1, if not add
zero.
Formulas
Page 4 of 7
A20 and if they are the same as A2, then it evaluates B2 through B20 to see how
many are 38 and adds 1 if true or 0 if false.
This is the longest formula I ever built (and I hope it stays that way). My customer
had a need to convert numbers from a negative taking 9 bytes to a number taking 8
bytes. We did this by taking a number like -5468 and changing to 546A. He called
this an OverPunch Code.
=IF(B19<0,TEXT(ABS(LEFT(B19,LEN(ABS(B19-
1))))&VLOOKUP(VALUE(RIGHT(B19,1)),LookSee,2,FALSE),"0"),B19)
Look at the number in cell B19. If it is a negative number, make it absolute or
positive, convert it to text, grab the rightmost digit of the number, take that digit
and use a lookup table in ‘LookSee’ to find a converter and tack that on the end of
the new number. After I did all this, I decided it was too long to re-type every month
and converted it to a user-defined function.
Find the number of working days between two dates excluding holidays.
=NETWORKDAYS(A1,B1,Holidays!A1:A5)
Where the 1st date is in cell A1 and the ending date is in cell B1. The holidays are in
a sheet called Holidays in cells A1 through A5
Suppose you know when someone came to work but you want to know when they
will have their 5 year anniversary
Assuming the date is in A7: =DATE(YEAR(A7)+5,MONTH(A7),DAY(A7))
Test for Multiple Conditions; then perform a calculation if BOTH conditions are met:
=IF(A1=5,IF(B1=10,VLOOKUP(A1,H3:I12,2),"2nd no match"),"1st no
match")
If the fist condition is met, then check for the second. If both conditions are satisfied, then
perform the VLOOKUP. Else tell me which condition was not met. These last could have
computations themselves. See illustration:
Formulas
Page 5 of 7
Test for 3 Conditions
=IF(B7>=5000,"high",IF(B7<=1000,"low","med"))
If the number is greater than or equal to 5000, then use the phrase "high," else if it
is equal to or below 1000 use "low." else the default is "med." [added 10/03/2000]
In a group of numbers, find the highest and get the table heading for that column
=INDEX($C$1:$K$1,MATCH(MAX($C4:$K4),$C4:$K4,0))
See the example below. In the table, find the column that has the highest number and
return the name from the column heading that matches the highest value. To download the
actual file, click here. Note: If you are using MS IE 3.x or higher, the file will probably
open directly in the browser interface. There is another example.
Formulas
Page 6 of 7
=MAX(E2:
174 -159 -142 155 100 E5)
Susan
Re-arrange a name from Last comma First to First Last
There are several ways to do this. The easiest is to insert a column after the one with
the names, then Data | Text to Columns and use the Comma as the separator.
Problems can occur if the writer used extraneous commas. OR do this in other
columns.
Old Last First
Flapdipple,
Flapdipple Harvey Q.
Harvey Q.
Barasch, Alan Barasch Alan
Gates, Bill Gates Bill
Heinlein, Robert
Heinlein Robert Anson
Anson
=LEFT(A6,FIND(",",A6,1)- =MID(A6,FIND(",",A6)+2,LEN(A6)-
1) FIND(",",A6)+2)
Formulas
Page 7 of 7