Upload
asad-mehmood
View
231
Download
0
Embed Size (px)
Citation preview
8/6/2019 Excel Formula Tips 2
http://slidepdf.com/reader/full/excel-formula-tips-2 1/6
J-Walk & Associates, Inc. Home Books Products Tips Downloads Resources Blog Support
Search
Making An Exact Copy Of A Range Of Formulas
Category: General / Formulas / General VBA | [Item URL]
Assume that A1:D10 on Sheet1 has a range of cells that contain formulas. Furthermore,
assume tha t you want to make a n exact copy of these formulas, beg inning in cell A11 on
Sheet1. By "exact," I mean a perfect replica -- the original cell references s hould not change.
If the formulas contain only absolute cell references, it's a piece of cake. Just use the standard
copy/paste commands. But if the formulas contain relative or mixed references, the standard
copy/paste technique won't work because the relative and mixed references w ill be ad justed
when the range is pasted.
If you're a VBA programmer, you can simply execute the follow ing code :
With Sheets("Sheet1")
.Range("A11:D20").Formula = .Range("A1:D10").Formula
End With
Following are step-by-step instructions to accomplish this task without using VBA (contributed
by Bob Umlas):
1. Select the source range (A1:D10 in this example).
2. Group the s ource she et w ith another empty sheet (say Sheet2). To do this, press C trl
while you click the sheet tab for Sheet2
3. Select Edit - Fill - Across wo rkshee ts (choose the All option in the dialog box).
4. Ungroup the sheets (click the she et tab for Sheet2)
5. In Sheet2, the copied range w ill be selected. Choose Edit - Cut.
6. Activate cell A11 (in Sheet2) and pres s Enter to pa ste the cut cells. A11.D20 will be
selected.
7. Re-group the shee ts. Press Ctl and click the sheet tab for Sheet18. Once again, use Edit - Fill - Across wo rksheets .
9. Activate Sheet1, and you'll find that A11:D20 contains an e xact replica of the formulas in
A1:D10.
Note: For another method of performing this task, see Making An Exact Copy Of A Range Of
Formulas, Take 2.
Comparing Two Lists With Conditional Formatting
Category: Formatting / Formulas | [Item URL]
Excel's C onditional Formatting feature has many use s. Suppose you need to compare two lists,
and identify the items tha t are different. The figure below show s an e xample. These lists
happen to contain text, but this technique also works w ith numeric data.
Excel TipsExcel has a long history, and it continues
to evolve and change. Consequently, the
tips provided here do not necessarily
apply to all versions of Excel.
In particular, the user interface for Excel
2007 (and later), is vastly different from
its predecessors. Therefore, the menu
commands listed in older tips, will not
correspond to the Excel 2007 (and later)
user interface.
All Tips
List all tips, by category
Browse all tips
Browse Tips by Category
General
Formatting
Formulas
Charts & Graphics
Printing
General VBA
CommandBars & Menus
UserForms
VBA Functions
Search for TipsSearch:
Go
Advanced Search
Tip BooksNeeds tips? Here are two books, with
nothing but tips:
converted by Web2PDFConvert.com
8/6/2019 Excel Formula Tips 2
http://slidepdf.com/reader/full/excel-formula-tips-2 2/6
The first list is in A2:B19, and this range is named OldList . The second list is in D2:E19, and the
range is named NewList . The ranges we re named using the Insert - Name - Define command.
Naming the ranges is not necess ary, but it makes them easier to w ork with.
As you can se e, items in OldList that do not appear in NewList are highlighted with a yellow
background . Items in NewList that do not appear in OldList are highlighted w ith a green
background. These colors are the result of Conditional Formatting.
How to do it
1. Start by selecting the OldList range.
2. Choo se Format - Cond itiona l Formatting
3. In the Conditional Formatting dialog box, use the drop -down list to choose Formula is.
4. Enter this formula:
=COUNTIF(NewList,A2)=0
5. Click the Format button and specify the formatting to apply when the condition is true (a
yellow background in this example).
6. Click OK
The cells in the NewList range will use a s imilar conditional formatting formula.
1. Select the NewList range.
2. Choo se Format - Cond itiona l Formatting3. In the Conditional Formatting dialog box, use the drop -down list to choose Formula is.
4. Enter this formula:
=COUNTIF(OldList,D2)=0
5. Click the Format button and specify the formatting to apply when the condition is true (a
green background in this example).
6. Click OK
Both of thes e cond itiona l formatting formulas use the COUNTIF function. This function counts
the number of times a p articular value appea rs in a range . If the formula returns 0, it means
that the item does not appear in the range. Therefore, the conditional formatting kicks in and
the cell's background color is changed.
The cell reference in the COUNTIF function should always be the upper left cell of the selected
range.
Locate Phantom Links In A Workbook
Category: Formulas | [Item URL]
Q. W henever I open a particular Excel workbook, I get a message asking if I want to
Contains more than 200 useful tips and
tricks for Excel 2007 | Other Excel 2007
books | Amazon link: John
Walkenbach's Favorite Excel 2007
Tips & Tricks
Contains more than 200 useful tips and
tricks for Excel | Other Excel 2003
books | Amazon link: John
Walkenbach's Favorite Excel Tips &
Tricks
converted by Web2PDFConvert.com
8/6/2019 Excel Formula Tips 2
http://slidepdf.com/reader/full/excel-formula-tips-2 3/6
update the links. I've examined every formula in the workbook, and I am absolutely
certain that the workbook contains no links to any other file. What can I do to convince
Excel that the workbook has no links?
You've encountered the infamous "phantom link" phenomenon. I've never known Excel to be
wrong about identifying links, so there's an excellent chance that your workbook does contain
one or more links -- but they a re probably not formula links.
Follow these steps to identify and e radicate a ny links in a w orkbook.
1. Select Edit, Links. In many cases , this command may not be available. If it is available, the
Links dialog bo x will tell you the name o f the so urce file for the link. Click the Change
Source button and change the link so it refers to the active file.2. Select Insert, Name, Define. Scroll through the list of names in the Define Name dialog bo x
and e xamine the Refers to bo x (see the figure be low). If a name refers to another
workbook or contains an e rroneous reference such a s #REF!, delete the name. This is, by
far, the mos t common cause of phantom links
3. If you have a cha rt in your workbook, click on each data s eries in the chart and examine
the SERIES formula disp layed in the formula ba r. If the SERIES formula refers to ano ther
wo rkbook, you've identified your link. To e liminate the link move or copy the cha rt's data
into the current workbook and recreate your chart.
4. If your workbook contains any custom dialog sheets , select each obje ct in each dialog
sheet and e xamine the formula ba r. If any obje ct conta ins a reference to anothe r
workbook, edit or delete the reference.
Next, save your workbook and the n re-open it. It should open up without asking you to
update the links.
Dealing With Negative Time Values
Category: Formulas | [Item URL]
Because Excel stores date s and times as numeric values, it's po ssible to add or sub tract one
from the other.
However, if you have a workbook containing only times (no da tes ), you may have discovered
that subtracting one time from another doesn't always work. Negative time values appea r as a
series of hash marks (########), even though you've ass igned the [h]:mm format to the
cells.
By default, Excel uses a date system that begins with January 1, 1900. A negative time valuegenerates a date/time combination that falls before this date, which is invalid.
The solution is to us e the optional 1904 date system. Select Tools, Options, click the Calculation
tab, and check the 1904 date system box to change the starting date to January 2, 1904. Your
negative times will now be displayed correctly, as s hown below.
Be careful if you workbook contains links to other files that don't use the 1904 date system. In
such a cas e, the mismatch of date systems could cause erroneous results.
converted by Web2PDFConvert.com
8/6/2019 Excel Formula Tips 2
http://slidepdf.com/reader/full/excel-formula-tips-2 4/6
Converting Non-numbers To Actual Values
Category: Formulas | [Item URL]
Q. I often import data into Excel from various applications, including Access. I've found
that values are sometimes imported as text, which means I can't use them in calculations
or with commands that require values. I've tried formatting the cells as values, with no
success. The only way I've found to convert the text into values is to edit the cell and then
press Enter. Is there an easier way to make these conversions?
This is a common problem in Excel. The goo d new s is the Excel 2002 is a ble to identify such
cells and you can e as ily correct them If you're us ing an olde r version of Excel, you can use this
method:
1. Select any empty cell
2. Enter the value 1 into that cell
3. Choose Edit, Copy
4. Select all the cells that need to be converted
5. Choose Edit, Paste Special
6. In the Paste Special dialog box, select the Multiply option, the n click OK.
This operation multiplies e ach cell by 1, and in the process converts the ce ll's conten ts to a
value.
Compare Ranges By Using An Array Formula
Category: Formulas | [Item URL]
In Excel, you can compare the cells in two ranges w ith an array formula. For instance, to see if
all of the values in A1:A100 a re identical to thos e in B1:B100, type this array formula:
=SUM(IF(A1:A100=B1:B100,0,1))
Note: This is an array formula and it must be entered using Ctrl-Shift-Enter .
The formula w ill return the number of correspond ing cells that a re different. If the formula
returns 0, it means that the two ranges are identical.
Calculate The Number Of Days In A Month
Category: Formulas | [Item URL]
Excel lacks a function for calculating the number of days in a pa rticular month, so you'll need to
construct your own formula.
If cell A1 contains a date , this formula will return the numbe r of days in the month:
=DAY(DATE(YEAR(A1),MONTH(A1)+1,1)-1)
Identify Formulas By Using Conditional Formatting
Category: Formulas | [Item URL]
How many times have you a cciden tally deleted o r overwritten cells containing formulas on ly to
discover the mistake a fter it's too late ? One s olution is to write-protect important cells.
Another approach is to give those cells a visual flag.
This clever technique wa s submitted by David Hager. It uses Conditional Formatting (available
in Excel 97 or later) to app ly special formatting to ce lls tha t contain formulas--something that's
not normally possible. With this technique you can set up your worksheet so that all formula
cells g et a yellow background, for example, or so that negative values a re in boldface.
Follow these steps:
1. Select Insert, Name, Define.
2. In the Define Name dialog box, enter the following in the 'Names in workbook' box
CellHasFormula
3. Then ente r the following formula in the "Refers to" box
=GET.CELL(48,INDIRECT("rc",FALSE))
4. Click Add , and then OK.
5. Select all the cells to which you want to app ly the conditional formatting.
6. Select Format, Conditional Formatting
7. In the Conditional Formatting dialog box, se lect Formula Is from the drop-down list, and
then enter this formula in the adjacent bo x (see the figure below ):
=CellHasFormula
converted by Web2PDFConvert.com
8/6/2019 Excel Formula Tips 2
http://slidepdf.com/reader/full/excel-formula-tips-2 5/6
8. Click the Format button and select the type of formatting you want for the cells that
contain a formula.
9. Click OK.
After you've completed these steps, every cell that contains a formula and is within the range
you se lected in Step 4 w ill display the formatting of your choice.
How does it work? The key component is creating a named formula in Steps 2 and 3. This
formula, unlike s tandard formulas, does n't reside in a cell, but it still acts like a formula by
returning a value -- in this case either 'True' or 'False'. The formula use s the GET.CELL function,
which is part of the XLM macro language (VBA's predecessor) and cannot be used directly in awo rksheet. Using a value o f 48 as the first argument for GET.CELL cause s the function to
return 'True' if the cell contains a formula. The INDIRECT function e sse ntially creates a
reference to e ach cell in the selected range.
Displaying Autofilter Criteria
Category: Formulas | [Item URL]
Excel's AutoFilter feature de finitely ranks right up the re when it comes to handy tools. This
feature, which you access with the Data, Filter, AutoFilter command, works with a range of cells
set up as a databa se o r list. When AutoFiltering is turned on, the row he aders d isplay drop-
down arrows that let you specify criteria (such as "Age greater than 30"). Rows that don't
match your criteria a re hidden , but they are red isplayed w hen you turn off AutoFiltering.
One problem w ith AutoFiltering is that you can't tell which criteria are in e ffect. Stephe n Bullen
deve loped a custom VBA workshee t function tha t displays the current AutoFilter criteria in a
cell. The instructions tha t follow a re for Excel 97 or late r.
Press Alt+F11 and insert a new module for the a ctive workbook. Then e nter the VBA code for
the FilterCriteria show n be low.
Function FilterCriteria(Rng As Range) As String
'By Stephen Bullen
Dim Filter As String
Filter = ""
On Error GoTo Finish
With Rng.Parent.AutoFilter
If Intersect(Rng, .Range) Is Nothing Then GoTo Finish
With .Filters(Rng.Column - .Range.Column + 1)
If Not .On Then GoTo Finish
Filter = .Criteria1
Select Case .Operator
Case xlAnd
Filter = Filter & " AND " & .Criteria2
Case xlOr
Filter = Filter & " OR " & .Criteria2
End Select
End With
End With
Finish:
FilterCriteria = Filter
End Function
After you've en tered the VBA code, you can use the function in your formulas. The single-cell
argument for the FilterCriteria function can refer to any cell within the column of interes t. The
formula w ill return the current AutoFilter criteria (if any) for the specified column. When you
turn AutoFiltering o ff, the formulas do n't display anything.
The figure below shows the FilterCriteria in action. The function is used in the cells in row 1.
For exam le cell A1 contains this formula:
converted by Web2PDFConvert.com
8/6/2019 Excel Formula Tips 2
http://slidepdf.com/reader/full/excel-formula-tips-2 6/6
=FilterCriteria(A3)
As you can se e, the list is currently filtered to show rows in which column A contains January,
column C contains a code of A or B, and column D contains a va lue grea ter than 125 (column B
is not filtered , so the formula in cell B1 displays nothing). The row s tha t don't match these
criteria are hidden.
Calculating A Conditional Average
Category: Formulas | [Item URL]
In the real world, a s imple average often isn't ade quate for your needs .
For example, an instructor might calculate student grades by averaging a series of tes t scores
but omitting the tw o lowes t scores. Or you might want to compute an a verage that ignores
both the highest and lowest values.
In cases such as these, the AVERAGE function w on't do, so you must create a more complex
formula. The following Excel formula computes the average of the values contained in a range
named "scores," but excludes the highest and lowe st values:
=(SUM(scores)-MIN(scores)-MAX(scores))/(COUNT(scores)-2)
Here's an example that calculates an a verage excluding the tw o lowe st scores:
=(SUM(scores)-MIN(scores)-SMALL(scores,2))/(COUNT(scores)-2)
Page 2 of 5 pages[Previous page] [Next page]
© Copyright 2011, J-Walk & Ass ociates, Inc.
This site is not affiliated with Microsoft C orporation.
Privacy Policy