Sie sind auf Seite 1von 15

Contents

Toms Tutorials For Excel: Listing Column Letters Across and Down .......................................................2
Toms Tutorials For Excel: Dynamic Summing From the Active Cell ........................................................3
Toms Tutorial For Excel: Summing For Multiple Conditions ...................................................................4
Toms Tutorials For Excel: Finding the Minimum and Maximum Numbers in a Filtered List ..................5
Toms Tutorials for Excel: Reverse Lookup ..............................................................................................6
Toms Tutorials For Excel: Deleting Duplicate Records ............................................................................7
Toms Tutorials For Excel: Parsing Data To Create and Populate Separate Workbooks .........................9
Toms Tutorials For Excel Viewing All Worksheets With One INDIRECT Formula.................................. 13

Toms Tutorials For Excel: Listing Column Letters Across and Down
Here are formulas to display the column letter in any individual cell, or to list column letters
horizontally across a row, or vertically down a column.
As shown in this first picture, you can display any cells column letter with the formula
=SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","")

You can use that same formula, =SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1",""), and copy it


across as such:

Here is the formula to list column letters vertically, as seen in the following picture:
=SUBSTITUTE(ADDRESS(1,ROW(),4),"1","")

Toms Tutorials For Excel: Dynamic Summing From the Active Cell
Heres a cool formula that you can plug into any cell, which will dynamically sum a list of numbers
from the top of the list to the cell of the row the formula is in.
For example, in the picture, cell C11 holds the formula
=SUM(B$3:INDEX(B:B,ROW()))
which sums the numbers in range B3:B11.

Toms Tutorial For Excel: Summing For Multiple Conditions


When you need to sum, average, or analyze data based on more than one condition,
the SUMPRODUCTfunction is an excellent tool for the job.
The pictured table shows an example of sales activity in the widget industry that includes several
different regions, companies, and prices. SUMPRODUCT helps you see how much of this depends on
these and those or these and those and them.
Download the free example workbook

Toms Tutorials For Excel: Finding the Minimum and Maximum


Numbers in a Filtered List
You can use the SUBTOTAL function to look up the minimum or maximum number in a filtered list.
In the picture, the formula in cell B1 that returns Sue Flays minimum sales number is
=SUBTOTAL(5,B5:B100)
The formula in cell B2 that returns Sue Flays maximum sales number is
=SUBTOTAL(4,B5:B100)
The first argument for SUBTOTAL is Function_Num, basically what type of function youre wanting to
perform:
1 AVERAGE 2 COUNT 3 COUNTA 4 MAX 5 MIN 6 PRODUCT 7 STDEV 8 STDEVP
9 SUM 10 VAR 11 VARP

Toms Tutorials for Excel: Reverse Lookup


As you probably know, the VLOOKUP function searches the first column of a range of cells and returns
a value from a cell in the same row. But what if your criteria item that is, what you are trying to look
up is not listed in the first column of the range? What if you need to return a value from a column to
the left of where your criteria is listed in the table?

In the picture, a department store keeps a daily table of transactions, with typical column fields
relating to their sales. To the right of the table are colored cells with examples for doing a reverse
lookup using the INDEX and MATCH functions.
In cell H2, the criteria for Order ID is manually entered to return its associated Product ID in the green
cell I2. Notice in the table that Order ID is located in column F and Product ID is located in column B,
so an alternative to VLOOKUP is needed.
In this example, the formula in cell I2 is
=INDEX(A1:F100,MATCH(H2,F1:F100,0),2)
You can interpret this formula as:
=INDEX(table-range, MATCH(criteria, criteria_column, match_exact), return_column_2)
Note that column 2 is column B, Product ID.
The second example in yellow cell I7 demonstrates the same principle. The formula there to find the
Sales associated with the criteria for Manager is
=INDEX(A1:F100,MATCH(H7,E1:E100,0),4)
In this example, it is the same table range of A1:F100, Tony as the Manager criteria is located in
column E, and the Sale associated with Tony would be in column D which is column #4 in the table.
Using INDEX and MATCH is a powerful combination for lookup routines, and it can be used for
looking up values to the right of the criteria column just as VLOOKUP does. Personally, I almost never
use VLOOKUP because I find INDEX and MATCH to be more versatile, not requiring the table to be
sorted in any way, nor having its column fields arranged in a certain order. Every Excel user has their
own preferences. If you are a dedicated VLOOKUP user, perhaps consider the INDEX and MATCH
approach, which you may find to be a valuable alternative.

Toms Tutorials For Excel: Deleting Duplicate Records


When you have a list of data, sometimes it is not enough to simply delete rows with duplicated
information based only on the items in one column. Multi-column lists can have duplicated records
based on the fact that every item in every column of a rows data matches that of another rows entire
data, cell for cell. In those cases, you need to compare a concatenated (combined) string of each
records (rows) data, and compare that to the concatenated strings of all the other rows.
Take a close look at this Before and After picture. In the original list, all the items in rows 5 and 7
match, as do all the items in rows 3 and 10. This is a short list for demonstration purposes. If your list
were a couple hundred thousand rows deep, such as an annual list of bank transactions or department
store purchases, you would need a fast and easy way to delete duplicated records. The macro that
follows the picture is one way to do the job. The comments in green explain each step.

Sub DeletingDuplicateRecords()
'Turn off ScreenUpdating to speed up the macro.
Application.ScreenUpdating = False
'Declare a range variable for the helper column being used.
Dim FilterRange As Range
'Define the range variables dynamic range.
Set FilterRange = Range("E1:E" & Cells(Rows.Count, 1).End(xlUp).Row)
'For efficiency, open a With structure for the FilterRange variable.
With FilterRange
'Enter the formula
'=SUMPRODUCT(($A$1:$A1=$A1)*($B$1:$B1=$B1)*($C$1:$C1=$C1)*($D$1:$D1=$D1))>1
'in all cells in column E (the helper column) that returns either TRUE
'if the record is a duplicate of a previous one, or FALSE if the record
'is unique among the records in all previous rows in the list.
.FormulaR1C1 = _
"=SUMPRODUCT((R1C1:RC1=RC1)*(R1C2:RC2=RC2)*(R1C3:RC3=RC3)*(R1C4:RC4=RC4))>1
"
'Turn the formulas into static values because they will be filtered,
'and maybe deleted if any return TRUE.

.Value = .Value
'AutoFilter the helper column for TRUE.
.AutoFilter Field:=1, Criteria1:="TRUE"
'Error bypass in case no TRUEs exist in the helper column.
On Error Resume Next
'This next line resizes the FilterRange variable to exclude the first row.
'Then, it deletes all visible filtered rows, abbreviated by SpecialCells
'constant number 12.
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(12).EntireRow.Delete
'Clear the Error object in case a run time error would have occurred,
'that is, if no TRUEs existed in the helper column to be deleted.
Err.Clear
'Close the With structure for the FilterRange variable object.
End With
'Exit (stop using) AutoFilter.
ActiveSheet.AutoFilterMode = False
'Clear all helper values (there would only be FALSEs at this moment).
'Note that Columns(5) means column E which is the fifth column from the
left
'on a standard Excel spreadsheet.
Columns(5).Clear
'Clear the range object variable to restore system memory.
Set FilterRange = Nothing
'Turn ScreenUpdating back on.
Application.ScreenUpdating = True
End Sub

Toms Tutorials For Excel: Parsing Data To Create and Populate


Separate Workbooks
Sometimes you need to organize a large table of data by creating and populating individual workbooks
based on rows belonging to each primary subject item.
For example, the next picture shows a table of company Stores and their activities. The table is actually
50,000 rows deep. You want to create a workbook for each Store, and copy that Stores data into its
own workbook.

In the next Before-and-After pictures, the main workbook is on the C drive in a folder named
YourFilePath. After the macro is run, each Store now has its own workbook with the the naming
convention of the Store name, followed by an underscore, then the current date in YYYMMDD format,
followed by the time in HHMMSS format. That way, youll be sure to keep every iteration of workbook
creation as a snapshot in time, without overriding it with a same-named file.

The below macro accomplishes this task, using AdvancedFilter to create a unique list of Store names.

Then, AutoFilter loops through that list to copy each Stores data into its own workbook. As a
convenience to the user, a message box pops up to confirm the job as complete, and it shows how
many unique Stores were parsed.
Finally, note that the original table was not altered in any way. Heres the macro:
Sub ParseStoresIntoWorkbooks()
'Use a With structure to prepare Excel.
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
End With
'Turn off autofilter and show all data.
ActiveSheet.AutoFilterMode = False
On Error Resume Next
ActiveSheet.ShowAllData
Err.Clear
With Cells
.EntireRow.Hidden = False
.EntireColumn.Hidden = False
End With
'Declare and define variables.
Dim xRow&, intCountUnique%
Dim strStore$
Dim strParsedStoreNameWB$, strDestinationFolderPath
Dim asn$, LastRow&, NextColumn&, FilterRange As Range
strDestinationFolderPath = ThisWorkbook.Path & "\"
asn = ActiveSheet.Name
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
NextColumn = Cells.Find(What:="*", After:=Range("A1"), _
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 2
Set FilterRange = _
ThisWorkbook.Worksheets(asn).Range("A1:A" & LastRow)
'List all unique Stores using AdvancedFilter.
FilterRange.AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Cells(1, NextColumn), Unique:=True
'Sort the list.
Cells(1, NextColumn).CurrentRegion.Sort _
Key1:=Cells(2, NextColumn), Order1:=xlAscending, Header:=xlYes
'Count how many unique Stores there are.
intCountUnique = WorksheetFunction.CountA(Columns(NextColumn)) - 1
'Loop through all unique Stores by filtering them, paste their
'data to a new workbook, and save the workbooks with date and time.
For xRow = 2 To Cells(Rows.Count, NextColumn).End(xlUp).Row
Workbooks.Add 1
With ThisWorkbook.Worksheets(asn)
.AutoFilterMode = False

strStore = .Cells(xRow, NextColumn).Value


End With
strParsedStoreNameWB = _
strStore & "_" & Format(VBA.Now, "YYYYMMDD_HHMMSS") & ".xls"
FilterRange.AutoFilter Field:=1, Criteria1:=strStore
FilterRange.SpecialCells(12).EntireRow.Copy Range("A1")
Columns(NextColumn).Clear 'unique list
Cells.Columns.AutoFit
ActiveWorkbook.SaveAs _
Filename:=strDestinationFolderPath & strParsedStoreNameWB
ActiveWorkbook.Close
Next xRow
'Re-activate this workbook and the source worksheet.
ThisWorkbook.Activate
Sheets(asn).Activate
'Turn off autofilter and show all data.
ActiveSheet.AutoFilterMode = False
On Error Resume Next
ActiveSheet.ShowAllData
Err.Clear
'Clear the unique list.
Columns(NextColumn).Clear
'Release object variables from system menory
Set FilterRange = Nothing
'Use a With structure to reset Excel.
With Application
.EnableEvents = True
.DisplayAlerts = True
.ScreenUpdating = True
End With
'Confirm for the user that the parsing is completed.
MsgBox "There were " & intCountUnique & " different Stores." & vbCrLf & _
"Their respective data has been consolidated into" & vbCrLf & _
"individual workbooks, all saved in the path" & vbCrLf & _
strDestinationFolderPath & ".", 64, "Done!"
End Sub

Toms Tutorials For Excel Viewing All Worksheets With One INDIRECT
Formula

Step 1
On the Summary worksheet in cell H2, Data Validation is applied, with the list of allowable entries
limited to the regions worksheet tab names. I selected cell H2 and pressed Alt+D+L to show the Data
Validation dialog box. In the Source field for List, I typed in those tab names separated by a comma, as
shown in the following picture.

Step 2
Still on the Summary worksheet, I selected the same range of cells that contain budget numbers for the
other regions. Its a valuable benefit from designing the workbook with all worksheets laid out the
same. In the active cell (B4 in this example) I typed the formula
=IF(LEN($H$2)=0,0,INDIRECT("'"&$H$2&"'!"&ADDRESS(ROW(),COLUMN())))
and I pressed Ctrl+Enter which applied that formula to all selected cells.

Step 3
Now while never leaving the Summary worksheet, its a simple matter of selecting the worksheet name
from the drop down list in cell H2 depending on which region I want to quickly see. In the following
picture, I selected the East Region.

Here are the East Regions numbers.

Das könnte Ihnen auch gefallen