Professional Documents
Culture Documents
Working in a complex worksheet, you may have encountered that annoying "#DIV/0!" error when the divisor of your formula is a zero. Using the IF function, you can create your own message for display when you divide by zero. The IF function will be like this: =IF (DIVISOR = 0,"Your Desired Text", DIVIDED/DIVISOR) The IF function evaluates the first parameter (DIVISOR = 0). If it's TRUE, it displays the second parameter ("Your Desired Text") in the cell. If it's FALSE, the function displays the third parameter (DIVIDED/DIVISOR) in the cell.
We'll use this sample data to demonstrate how easily you can transpose the layout of your data.
After working with the data for a while, you decide you'd rather have the current set of row labels (months) running across the columns. Whatever you do, don't even think about rekeying the data.
You'll find the best solution under the Paste Special menu. Start by selecting and copying your entire data range. Click on a new location in your sheet, then go to Edit | Paste Special and select the Transpose check box, as shown in Figure Q. Click OK, and Excel will transpose the column and row labels and data, as shown in Figure R. Figure Q
The Transpose option lets you rearrange your data with just a few clicks.
Figure R
Here's what our data looks like after we copied and pasted our data using the Paste Special | Transpose option.
Note
You aren't limited to using the Paste Special | Transpose option to rearrange multiple rows and columns of data. It works just as well when you need to turn a single row of labels into a column, or vice-versa.
3. Repeat rows on top when printing, show table headers on every page
When you are on the sheet view, just hit menu > file > page setup, go to the last tab, specify rows to repeat. You can repeat columns while printing as well from the same menu.
4. Find total working days between any two dates, including holidays
If you work on project plans, gantt charts alot, this can be totally handy. Just type =networkdays(start date, end date, list of holidays) to fetch the number of working days. In the above sample you can see the number of working days between New years day and September first of this year (labor day).
6. Named Formula
To make a Name refer to a constant formula e.g. "TaxRate", go to Insert>Name>Define and type TaxRate in the "Names in Workbook" box and 36% in the "Refers To". Now enter =(10*TaxRate) anywhere on the Worksheet.
7. Nested Formulas
To help write nested formulas (more than 1 formula in a single cell) use the "Paste Function" i.e. Insert>Function or Shift+F3. Select the function that you need, enter the reference, number or text then select the drop arrow to the left of the formula bar to add more Formulas. Doing it this way ensures all your parentheses are in the correct places.
12. Trick number one is highlighting duplicate entries in a column. Here is what you do:
1. Go to the first cell in the column you want to search for duplicates and pull up the conditional formatting menu 2. Change the pull-down box to Formula Is 3. Use the following formula:
=COUNTIF($A$1:$A$20, A2)>1
4. Pick appropriate formatting then grab the format painter thingy and drag it all over the other columns in range A1 to A20 (or whatever range you want)
13. Common situations. To get the first name of a person, To calculate mortgage payments To get nth largest number in a range To get nth smallest number in a range To generate a random phone number To count positive values in a range To remove unnecessary spaces Format a number as SSN using formulas To find age of a person based on DOB To get proper fraction from a number Counts number of cells with numbers in them Counts number of cells with anything in them Show values after decimal point only when number is less than one =left(name,find( ,name)-1) =PMT(interest-rate,number-of-payments,how-much-loan) =large(range,n) = small(range,n) =randbetween(1000000000,9999999999) =countif(range,>0) =trim(text) =text(ssn-text,000-00-0000) =TEXT((NOW()-birth_date)&",yy years" m months" dd days") =text(fraction, ?/?) =COUNT() =COUNTA()
Sub HideRows() Application.ScreenUpdating = False Dim i As Integer Dim RStart As Range Dim REnd As Range Set RStart = Range("A2") Set REnd = Sheets("YourSheetName").Range("A65536").End(xlUp).Offset(0, 3) Range(RStart, REnd).Select On Error Resume Next With Selection .EntireRow.Hidden = False For i = 1 To .Rows.Count If WorksheetFunction.CountBlank(.Rows(i)) = 4 Then .Rows(i).EntireRow.Hidden = True End If Next i End With Set RStart = Nothing Set REnd = Nothing Range("A1").Select Application.ScreenUpdating = True End Sub
Use Excel conditional formatting to highlight duplicate entries in a column: 1. Select range A2:A11 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =COUNTIF($A$2:$A$11,A 2)>1 5. Click the Format button. 6. Select a font colour for highlighting. 7. Click OK, click OK
10
8. Filter the list, and the shading will alternate in the visible rows.
14
This macro executes whenever the workbook is opened, and sets the EnableSelection property of Sheet1 to xlUnlockedCells. The technique can be circumvented by changing the EnableSelection property to its default value (xlNoRestrictions). Few users know about this dodge, however.
15
26. Filtering.
Excel Advanced Filter Introduction
1. Excel Advanced Filter--Introduction a) Apply an Excel Advanced Filter b) Filter Unique Records c) Extract Data to Another Worksheet d) Setting up the Criteria Range e) Using Wildcards in Criteria f) Criteria Examples 2. Advanced Filters -- Complex Criteria For Excel 2003 instructions, see Excel 2003 Advanced Filter Introduction
Download zipped Excel advanced filter workbook with sample data and criteria.
16
After the Excel advanced filter is applied, orders with a total greater than $500 will remain visible. Other operators include: < less than <= less than or equal to >= greater than or equal to <> not equal to
17
3. You can choose to filter the list in place, or copy the results to another location. 4. Excel should automatically detect the list range. If not, you can select the cells on the worksheet. 5. Select the criteria range on the worksheet 6. If you are copying to a new location, select a starting cell for the copy Note: If you copy to another location, all cells below the extract range will be cleared when the Advanced Filter is applied. 7. Click OK
4. For the List range, select the column(s) from which you want to extract the unique values. 5. Leave the Criteria Range blank. 6. Select a starting cell for the Copy to location. 7. Add a check mark to the Unique records only box. 8. Click OK.
19
12. Click OK
1.
the customer must be MegaMart AND the product must be Cookies AND the total must be greater than 500.
Criteria on different rows are joined with an OR operator. In the second example at right -
2.
the customer must be MegaMart OR the product must be Cookies OR the total must be greater than 500.
By using multiple rows, you can combine the AND 3. and OR operators. In the third example at right -
the customer must be MegaMart AND the product must be Cookies OR the product must be Cookies AND the total must be greater than 500.
20
The asterisk (*) wildcard character represents any number of characters in that position, including zero characters. In this example, any customer whose name contains "mart" will pass through the Excel advanced filter.
The ? wildcard
The question mark (?) wildcard character represents one characters in that position. In this example any 4letter product that begins with c, and ends with ke, will pass through the Excel advanced filter. Both Coke and Cake are in the filtered results.
21
The ~ wildcard
The tilde (~) wildcard character lets you search for characters that are used as wildcards. In the first example at right, an asterisk is in the criteria cell -Good*Eats -- so any products that begins with Good and ends with Eats, will pass through the Excel advanced filter. To find only the product that is named Good*Eats, use a tilde character in front of the asterisk in the critereia cell. -- Good~*Eats.
To extract a list of items in a range, you can use two columns for one of the fields. In this example, two columns are used for the Date field. If you enter two criteria on the same row in the criteria range, you create an AND statement. In this example, any records that are extracted must be greater than or equal to the first date AND less than
22
23
If you enter criteria on different rows in the criteria range, you create an OR statement. In this example, extracted records must meet both conditions in row 2 OR both conditions in row 3. In the results, only the records for MegaMart Cookies, or for MiniMart Milk will be in the filter results.
Extract Items with Specific Text
When you use text as criteria with an Excel advanced filter, Excel finds all items that begin For example, if you type "Ice" as a criterion, Excel finds "Ice", "Ice Cream" and "Ice Milk" To extract only the records for Ice, use the following format: ="=Ice"
24
27. Use the Excel Custom Functions of Feet () and LenText to Convert Lengths in Feet and Inches to Decimal Feet and Back.
I have an Excel spreadsheet with a column of lengths in the format of 12' 6 7/8". How can I convert this to decimal feet? I don't want to split the column into two parts. Then, how can I feet and inches in Excel?. The custom function feet() shown below will take a text field in the format that you describe decimal feet. The custom function LenText will convert a decimal number of feet into a text field showin fractional inches to the nearest 1/32". To enter the custom function,
Start the VB editor with alt-F11. Insert>Module. Insert>Procedure. Type feet as the name of the procedure and indicate it is a function. Then, copy the following code:
Public Function feet(LenString As String) Dim FootSign As Integer Dim InchSign As Integer Dim SpaceSign As Integer Dim FracSign As Integer Dim InchString As String Dim Word2 As String ' Copyright 1999, 2005 MrExcel.com LenString = Application.WorksheetFunction.Trim(LenString) 'The find function returns an error when the target is not found 'Resume Next will prevent VBA from halting execution. On Error Resume Next FootSign = Application.WorksheetFunction.Find("'", LenString) If IsEmpty(FootSign) Or FootSign = 0 Then ' There are no feet in this expression feet = 0 FootSign = 0 Else feet = Val(Left(LenString, FootSign - 1)) End If ' Handle the case where the foot sign is the last character If Len(LenString) = FootSign Then Exit Function ' Isolate the inch portion of the string InchString = Application.WorksheetFunction.Trim(Mid(LenString, FootSign + 1))
25
' Strip off the inch sign, if there is one InchSign = Application.WorksheetFunction.Find("""", InchString) If Not IsEmpty(InchSign) Or InchSign = 0 Then InchString = Application.WorksheetFunction.Trim(Left(InchString, InchSign - 1)) End If ' Do we have two words left, or one? SpaceSign = Application.WorksheetFunction.Find(" ", InchString) If IsEmpty(SpaceSign) Or SpaceSign = 0 Then ' There is only one word here. Is it inches or a fraction? FracSign = Application.WorksheetFunction.Find("/", InchString) If IsEmpty(FracSign) Or FracSign = 0 Then 'This word is inches feet = feet + Val(InchString) / 12 Else ' This word is fractional inches feet = feet + (Val(Left(InchString, FracSign - 1)) / Val(Mid(InchString, FracSign + 1))) / 12 End If Else ' There are two words here. First word is inches feet = feet + Val(Left(InchString, SpaceSign - 1)) / 12 ' Second word is fractional inches Word2 = Mid(InchString, SpaceSign + 1) FracSign = Application.WorksheetFunction.Find("/", Word2) If IsEmpty(FracSign) Or FracSign = 0 Then ' Return an error feet = "VALUE!" Else If FracSign = 0 Then feet = "VALUE!" Else feet = feet + (Val(Left(Word2, FracSign - 1)) / Val(Mid(Word2, FracSign + 1))) / 12 End If End If End If End Function
26
FracText = "" ElseIf InchIn >= (11 + (31.4999999 / 32)) Then NbrFeet = NbrFeet + 1 NbrInches = 0 FracText = "" ElseIf Numerator = Denominator Then NbrInches = NbrInches + 1 FracText = "" Else Do ' If the numerator is even, divide both numerator and divisor by 2 If Numerator = Application.WorksheetFunction.Even(Numerator) Then Numerator = Numerator / 2 Denominator = Denominator / 2 Else FracText = " " & Numerator & "/" & Denominator Exit Do End If Loop End If LenText = NbrFeet & "' " & NbrInches & FracText & """" End Function
Column A shows the original text. Column B correctly converts to feet any values that contain feet, inches, and / or fractional inches. Note that if you do not include the foot sign, the value is assumed to be inches. (row 12). If the fractional portion of the inches is not valid, Value! is returned (row 13). Note: Thanks to Dale Richmond from Kansas City who provided an update in October 2007 to prevent an answer of 1 foot 12 inches when a number greater than 1.999 is passed to the function.
27