Вы находитесь на странице: 1из 6

J-Walk & Associates, Inc.

Home Books Products Tips Dow nloads Resources Blog Support


Search

Making An Exact Copy Of A Range Of Formulas


Excel Tips
Excel has a long history, and it continues C ategory: General / Formulas / General VBA | [Item URL]
to evolve and change. C onsequently, the
tips provided here do not necessarily Assume that A1:D10 on Sheet1 has a range of cells that contain formulas. Furthermore,
apply to all versions of Excel. assume that you w ant to make an exact copy of these formulas, beginning in cell A11 on
Sheet1. By "exact," I mean a perfect replica -- the original cell references should not change.
In particular, the user interface for Excel
2007 (and later), is vastly different from
its predecessors. Therefore, the menu If the formulas contain only absolute cell references, it's a piece of cake. Just use the standard
commands listed in older tips, will not copy/paste commands. But if the formulas contain relative or mixed references, the standard
correspond to the Excel 2007 (and later) copy/paste technique w on't w ork because the relative and mixed references w ill be adjusted
user interface. w hen the range is pasted.

All Tips If you're a VBA programmer, you can simply execute the follow ing code:
List all tips, by category
Browse all tips
With Sheets("Sheet1")
.Range("A11:D20").Formula = .Range("A1:D10").Formula
End With
Browse Tips by Category
General Follow ing are step-by-step instructions to accomplish this task w ithout using VBA (contributed
Formatting by Bob Umlas):
Formulas
1. Select the source range (A1:D10 in this example).
Charts & Graphics
Printing 2. Group the source sheet w ith another empty sheet (say Sheet2). To do this, press Ctrl
w hile you click the sheet tab for Sheet2
General VBA
CommandBars & Menus 3. Select Edit - Fill - Across w orksheets (choose the All option in the dialog box).
UserForms 4. Ungroup the sheets (click the sheet tab for Sheet2)
VBA Functions 5. In Sheet2, the copied range w ill be selected. Choose Edit - Cut.
6. Activate cell A11 (in Sheet2) and press Enter to paste the cut cells. A11.D20 w ill be
Search for Tips selected.
Search: 7. Re-group the sheets. Press Ctl and click the sheet tab for Sheet1
Go 8. Once again, use Edit - Fill - Across w orksheets.
Advanced Search 9. Activate Sheet1, and you'll find that A11:D20 contains an exact replica of the formulas in
A1:D10.
Tip Books Note: For another method of performing this task, see Making An Exact Copy Of A Range Of
Needs tips? Here are two books, with Formulas, Take 2.
nothing but tips:

Comparing Two Lists With Conditional Formatting


C ategory: Formatting / Formulas | [Item URL]

Excel's Conditional Formatting feature has many uses. Suppose you need to compare tw o lists,
and identify the items that are different. The figure below show s an example. These lists
happen to contain text, but this technique also w orks w ith numeric data.

converted by Web2PDFConvert.com
C ontains more than 200 useful tips and
tricks for Excel 2007 | Other Excel 2007
books | Amazon link: John
Walkenbach's Favorite Excel 2007
Tips & Tricks

C ontains more than 200 useful tips and


tricks for Excel | Other Excel 2003
books | Amazon link: John
Walkenbach's Favorite Excel Tips &
Tricks

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 w ere named using the Insert - Name - Define command.
Naming the ranges is not necessary, but it makes them easier to w ork w ith.

As you can see, items in OldList that do not appear in NewList are highlighted w ith 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. Choose Format - Conditional Formatting
3. In the Conditional Formatting dialog box, use the drop-dow n list to choose Formula is.
4. Enter this formula:
=COUNTIF(NewList,A2)=0
5. Click the Format button and specify the formatting to apply w hen the condition is true (a
yellow background in this example).
6. Click OK

The cells in the NewList range w ill use a similar conditional formatting formula.

1. Select the NewList range.


2. Choose Format - Conditional Formatting
3. In the Conditional Formatting dialog box, use the drop-dow n list to choose Formula is.
4. Enter this formula:
=COUNTIF(OldList,D2)=0
5. Click the Format button and specify the formatting to apply w hen the condition is true (a
green background in this example).
6. Click OK
Both of these conditional formatting formulas use the COUNTIF function. This function counts
the number of times a particular value appears 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 alw ays be the upper left cell of the selected
range.

Locate Phantom Links In A Workbook


C ategory: Formulas | [Item URL]

Q. Whenever I open a particular Excel workbook, I get a message asking if I want to

converted by Web2PDFConvert.com
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 know n Excel to be
w rong about identifying links, so there's an excellent chance that your w orkbook does contain
one or more links -- but they are probably not formula links.

Follow these steps to identify and eradicate any 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 box w ill tell you the name of the source 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 box
and examine the Refers to box (see the figure below ). If a name refers to another
w orkbook or contains an erroneous reference such as #REF!, delete the name. This is, by
far, the most common cause of phantom links
3. If you have a chart in your w orkbook, click on each data series in the chart and examine
the SERIES formula displayed in the formula bar. If the SERIES formula refers to another
w orkbook, you've identified your link. To eliminate the link move or copy the chart's data
into the current w orkbook and recreate your chart.
4. If your w orkbook contains any custom dialog sheets, select each object in each dialog
sheet and examine the formula bar. If any object contains a reference to another
w orkbook, edit or delete the reference.
Next, save your w orkbook and then re-open it. It should open up w ithout asking you to
update the links.

Dealing With Negative Time Values


C ategory: Formulas | [Item URL]

Because Excel stores dates and times as numeric values, it's possible to add or subtract one
from the other.

How ever, if you have a w orkbook containing only times (no dates), you may have discovered
that subtracting one time from another doesn't alw ays w ork. Negative time values appear as a
series of hash marks (########), even though you've assigned the [h]:mm format to the
cells.

By default, Excel uses a date system that begins w ith January 1, 1900. A negative time value
generates a date/time combination that falls before this date, w hich is invalid.

The solution is to use 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 w ill now be displayed correctly, as show n below .

Be careful if you w orkbook contains links to other files that don't use the 1904 date system. In
such a case, the mismatch of date systems could cause erroneous results.

converted by Web2PDFConvert.com
Converting Non-numbers To Actual Values
C ategory: 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 good new s is the Excel 2002 is able to identify such
cells and you can easily correct them If you're using an older 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, then click OK.
This operation multiplies each cell by 1, and in the process converts the cell's contents to a
value.

Compare Ranges By Using An Array Formula


C ategory: Formulas | [Item URL]

In Excel, you can compare the cells in tw o ranges w ith an array formula. For instance, to see if
all of the values in A1:A100 are identical to those 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 corresponding cells that are different. If the formula
returns 0, it means that the tw o ranges are identical.

Calculate The Number Of Days In A Month


C ategory: Formulas | [Item URL]

Excel lacks a function for calculating the number of days in a particular month, so you'll need to
construct your ow n formula.

If cell A1 contains a date, this formula w ill return the number of days in the month:

=DAY(DATE(YEAR(A1),MONTH(A1)+1,1)-1)

Identify Formulas By Using Conditional Formatting


C ategory: Formulas | [Item URL]

How many times have you accidentally deleted or overw ritten cells containing formulas only to
discover the mistake after it's too late? One solution is to w rite-protect important cells.
Another approach is to give those cells a visual flag.

This clever technique w as submitted by David Hager. It uses Conditional Formatting (available
in Excel 97 or later) to apply special formatting to cells that contain formulas--something that's
not normally possible. W ith this technique you can set up your w orksheet so that all formula
cells get a yellow background, for example, or so that negative values are in boldface.

Follow these steps:

1. Select Insert, Name, Define.


2. In the Define Name dialog box, enter the follow ing in the 'Names in w orkbook' box
CellHasFormula
3. Then enter the follow ing formula in the "Refers to" box
=GET.CELL(48,INDIRECT("rc",FALSE))
4. Click Add, and then OK.
5. Select all the cells to w hich you w ant to apply the conditional formatting.
6. Select Format, Conditional Formatting
7. In the Conditional Formatting dialog box, select Formula Is from the drop-dow n list, and
then enter this formula in the adjacent box (see the figure below ):
=CellHasFormula

converted by Web2PDFConvert.com
8. Click the Format button and select the type of formatting you w ant for the cells that
contain a formula.
9. Click OK.
After you've completed these steps, every cell that contains a formula and is w ithin the range
you selected in Step 4 w ill display the formatting of your choice.

How does it w ork? The key component is creating a named formula in Steps 2 and 3. This
formula, unlike standard formulas, doesn'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 uses the GET.CELL function,
w hich is part of the XLM macro language (VBA's predecessor) and cannot be used directly in a
w orksheet. Using a value of 48 as the first argument for GET.CELL causes the function to
return 'True' if the cell contains a formula. The INDIRECT function essentially creates a
reference to each cell in the selected range.

Displaying Autofilter Criteria


C ategory: Formulas | [Item URL]

Excel's AutoFilter feature definitely ranks right up there w hen it comes to handy tools. This
feature, w hich you access w ith the Data, Filter, AutoFilter command, w orks w ith a range of cells
set up as a database or list. W hen AutoFiltering is turned on, the row headers display drop-
dow n arrow s that let you specify criteria (such as "Age greater than 30"). Row s that don't
match your criteria are hidden, but they are redisplayed w hen you turn off AutoFiltering.

One problem w ith AutoFiltering is that you can't tell w hich criteria are in effect. Stephen Bullen
developed a custom VBA w orksheet function that displays the current AutoFilter criteria in a
cell. The instructions that follow are for Excel 97 or later.

Press Alt+F11 and insert a new module for the active w orkbook. Then enter the VBA code for
the FilterCriteria show n below .

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 entered the VBA code, you can use the function in your formulas. The single-cell
argument for the FilterCriteria function can refer to any cell w ithin the column of interest. The
formula w ill return the current AutoFilter criteria (if any) for the specified column. W hen you
turn AutoFiltering off, the formulas don't display anything.

The figure below show s the FilterCriteria in action. The function is used in the cells in row 1.
For example, cell A1 contains this formula:

converted by Web2PDFConvert.com
=FilterCriteria(A3)
As you can see, the list is currently filtered to show row s in w hich column A contains January,
column C contains a code of A or B, and column D contains a value greater than 125 (column B
is not filtered, so the formula in cell B1 displays nothing). The row s that don't match these
criteria are hidden.

Calculating A Conditional Average


C ategory: Formulas | [Item URL]

In the real w orld, a simple average often isn't adequate for your needs.

For example, an instructor might calculate student grades by averaging a series of test scores
but omitting the tw o low est scores. Or you might w ant to compute an average that ignores
both the highest and low est values.

In cases such as these, the AVERAGE function w on't do, so you must create a more complex
formula. The follow ing Excel formula computes the average of the values contained in a range
named "scores," but excludes the highest and low est values:

=(SUM(scores)-MIN(scores)-MAX(scores))/(COUNT(scores)-2)

Here's an example that calculates an average excluding the tw o low est scores:

=(SUM(scores)-MIN(scores)-SMALL(scores,2))/(COUNT(scores)-2)

Page 2 of 5 pages
[Previous page] [Next page]

© Copyright 2011, J-Walk & A ssociates, Inc.


This site is not affiliated with Microsoft Corporation.
Privacy Policy

converted by Web2PDFConvert.com

Вам также может понравиться