Upload
anurag
View
231
Download
0
Embed Size (px)
Citation preview
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 1/30
Pivot tables are one of Excel's most powerful features. A pivot table allows
you to extract the signicance from a large, detailed data set.
Our data set consists of !" rows and # elds. Order $%, Product, &ategory,
Amount, %ate and &ountry.
$nsert a Pivot able o insert a pivot table, execute the following steps.
!. &lic( any single cell inside the data set.
. On the $nsert tab, clic( Pivotable.
he following dialog box appears. Excel automatically selects the data for
you. he default location for a new pivot table is )ew *or(sheet.
+. &lic( O.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 2/30
%rag elds he Pivotable eld list appears. o get the total amount exported of each
product, drag the following elds to the di-erent areas.
!. Product ield to the /ow 0abels area.
. Amount ield to the 1alues area.
+. &ountry ield to the /eport ilter area.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 3/30
2elow you can nd the pivot table. 2ananas are our main export product.
hat's how easy pivot tables can be3
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 4/30
4ort o get 2anana at the top of the list, sort the pivot table.
!. &lic( any cell inside the otal column.
. he Pivotable ools contextual tab activates. On the Options tab, clic( the
4ort 0argest to 4mallest button 56A7.
/esult.
ilter2ecause we added the &ountry eld to the /eport ilter area, we can lter
this pivot table by &ountry. or example, which products do we export the
most to rance8
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 5/30
!. &lic( the lter drop9down and select rance.
/esult. Apples are our main export product to rance.
)ote: you can use the standard lter 5triangle next to Product7 to only show
the totals of specic products.
&hange 4ummary &alculation2y default, Excel summari;es your data by either summing or counting the
items. o change the type of calculation that you want to use, execute the
following steps.
!. &lic( any cell inside the otal column.
. /ight clic( and clic( on 1alue ield 4ettings...
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 6/30
+. &hoose the type of calculation you want to use. or example, clic( &ount.
". &lic( O.
/esult. !# out of the < orders to rance were 'Apple' orders.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 7/30
wo9dimensional Pivot able$f you drag a eld to the /ow 0abels area and &olumn 0abels area, you can
create a two9dimensional pivot table. or example, to get the total amount
exported to each country, of each product, drag the following elds to the
di-erent areas.
!. &ountry ield to the /ow 0abels area.
. Product ield to the &olumn 0abels area.
+. Amount ield to the 1alues area.
". &ategory ield to the /eport ilter area.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 8/30
2elow you can nd the two9dimensional pivot table.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 9/30
o easily compare these numbers, create a pivot chart and apply a lter.
=aybe this is one step too far for you at this stage, but it shows you one of
the many other powerful pivot table features Excel has to o-er.
%o you li(e this free website8 Please follow us on
>oogle?
Learn more about pivot tables, use theside menu >>
>o to op: Pivot ables @ >o to )ext &hapter: ables
• &hapter
o Pivot ables
• 0earn more, it's easy•
o >roup Pivot able $tems
>o
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 10/30
o =ulti9level Pivot able
o reuency %istribution
o Pivot &hart
o 4licers
o Bpdate Pivot able
o &alculated ieldC$tem
•
%ownload Excel ileo pivot9tables.xls
ollow Excel Easy
&OPD/$> 5&7 F!F9F!G ***.EH&E09EA4D.&O=. EH&E0 P$1O A20E4. A00 /$>4 /E4E/1E%.EH&E0 F!F BO/$A0 @ O* O
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 11/30
What is a Macro?
A Microsoft Office Macro (as this functionality applies to several of the
MS Office Applications) is simply Visual Basic for Applications (VBA)
code saved inside a document. For a comparable analogy thin! of a
document as "#M$ and a macro as %avascript. &n much of the same
'ay that %avascript can manipulate "#M$ on a 'ebpage a macro can
manipulate a document.
Macros are incredibly po'erful and can do pretty much anything your
imagination can conure. As a (very) short list of functions you can do
'ith a macro
• Apply style and formatting.
• Manipulate data and te*t.
• +ommunicate 'ith data sources (database te*t files etc.).
• +reate entirely ne' documents.
• Any combination in any order of any of the above.
Creating a Macro: An Explanation by Example
,e start 'ith your garden variety +SV file. -othing special here ust a
/01/ set of numbers bet'een / and // 'ith both a ro' and column
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 12/30
header. Our goal is to produce a 'ell formatted presentable data
sheet 'hich includes summary totals for each ro'.
As 'e stated above a macro is VBA code but one of the nice things
about 2*cel is you can create3record them 'ith 4ero coding re5uired 6
as 'e 'ill do here.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 13/30
#o create a macro go to Vie' 7 Macros 7 8ecord Macro.
Assign the macro a name (no spaces) and clic! O9.
Once this is done all of your actions are recorded 6 every cell change
scroll action 'indo' resi4e you name it.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 14/30
#here are a couple of places 'hich indicate 2*cel is record mode.
One is by vie'ing the Macro menu and noting that Stop 8ecording
has replaced the option for 8ecord Macro.
#he other is in the bottom right corner. #he :stop; icon indicates it is in
macro mode and pressing here 'ill stop the recording (li!e'ise 'hen
not in record mode this icon 'ill be the 8ecord Macro button 'hich
you can use instead of going to the Macros menu).
-o' that 'e are recording our macro let;s apply our summary
calculations. First add the headers.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 15/30
-e*t apply the appropriate formulas (respectively)
• <S=M(B191)
• <AV28A>2(B191)
• <M&-(B191)
• <MA?(B191)
• <M2@&A-(B191)
-o' highlight all the calculation cells and drag the length of all our
data ro's to apply the calculations to each ro'.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 16/30
Once this is done each ro' should display their respective
summaries.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 17/30
-o' 'e 'ant to get the summary data for the entire sheet so 'e
apply a fe' more calculations
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 18/30
8espectively
• <S=M($1$1)
• <AV28A>2(B191) This must be calculated across all data
because the average of the row averages does not necessarily
equal the average of all the values.
• <M&-(-1-1)
• <MA?(O1O1)
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 19/30
• <M2@&A-(B191) *Calculated across all data for the same
reason as above.
-o' that the calculations are done 'e 'ill apply the style and
formatting. First apply general number formatting across all the cells
by doing a Select All (either +trl A or clic! the cell bet'een the ro'
and column headers) and select the C+omma StyleD icon under the
"ome menu.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 20/30
-e*t apply some visual formatting to both the ro' and column
headers
• Bold.
• +entered.
• Bac!ground fill color.
And finally apply some style to the totals.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 21/30
,hen all is finished this is 'hat our data sheet loo!s li!e
Since 'e are satisfied 'ith the results stop the recording of the
macro.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 22/30
+ongratulations 6 you have ust created an 2*cel macro.
&n order to use our ne'ly recorded macro 'e have to save our 2*cel
,or!boo! in a macro enabled file format. "o'ever before 'e do that
'e first need to clear all the e*isting data so that it is not embedded in
our template (the idea being every time 'e use this template 'e 'ill
import the most upEtoEdate data).
#o do this select all cells and delete them.
,ith the data no' cleared (but the macros still included in the 2*cel
file) 'e 'ant to save the file as a macro enabled template (?$#M) file.
&t is important to note that if you save this as a standard template
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 23/30
(?$#?) file then macros 'ill not be able to be run from it. Alternately
you can save the file as a legacy template (?$#) file 'hich 'ill allo'
macros to be run.
Once you have saved the file as a template go ahead and close
2*cel.
Using an Excel Macro
Before covering ho' 'e can apply this ne'ly recorded macro it is
important to cover a fe' points about macros in general
• Macros can be malicious.
• See the point above.
VBA code is actually 5uite po'erful and can manipulate files outsideof the scope of the current document. For e*ample a macro could
alter or delete random files in your My @ocuments folder. As such it is
important to ma!e sure you only run macros from trusted sources.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 24/30
#o put our data format macro to use open the 2*cel #emplate file
'hich 'as created above. ,hen you do this assuming you have
standard security settings enabled you 'ill see a 'arning across the
top of the 'or!boo! 'hich says that macros are disabled. Because 'etrust a macro created by ourselves clic! the :2nable +ontent; button.
=p ne*t 'e are going to import the latest data set from a +SV (this is
the source the 'or!sheet used to create our macro).
#o complete the import of the +SV file you may have to set a fe'
options in order for 2*cel to interpret it correctly (e.g. delimiter
headers present etc.).
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 25/30
Once our data is imported simply go to the Macros menu (under the
Vie' tab) and select Vie' Macros.
&n the resulting dialog bo* 'e see the CFormat@ataD macro 'erecorded above. Select it and clic! 8un.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 26/30
Once running you may see the cursor ump around for a fe'
moments but as it does you 'ill see the data being
manipulated exactly as 'e recorded it. ,hen all is said and done it
should loo! ust li!e our original 6 e*cept 'ith different data.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 27/30
Looking Under the Hood: What Makes a Macro Work
As 'e have mentioned a couple of times a macro is driven by Visual
Basic for Applications (VBA) code. ,hen you CrecordD a macro 2*cel
is actually translating everything you do into its respective VBA
instructions. #o put it simply 6 you don;t have to 'rite any code
because 2*cel is 'riting the code for you.
#o vie' the code that ma!es our macro run from the Macros dialog
clic! the 2dit button.
#he 'indo' that opens displays the source code that 'as recorded
from our actions 'hen creating the macro. Of course you can edit this
code or even create ne' macros entirely inside of the code 'indo'.
,hile the recording action used in this article 'ill li!ely fit most needs
more highly customi4ed actions or conditional actions 'ould re5uire
you to edit the source code.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 28/30
Taking !r Example ne "tep #arther$
"ypothetically assume our source data file data.csv is produced by
an automated process 'hich al'ays saves the file to the same
location (e.g. [email protected] is al'ays the most recent data). #he
process of opening this file and importing it can be easily made into a
macro as 'ell
. Open the 2*cel #emplate file containing our CFormat@ataD
macro.
1. 8ecord a ne' macro named C$oad@ataD.
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 29/30
G. ,ith the macro recording import the data file li!e you normally
'ould.
H. Once the data is imported stop recording the macro.
I. @elete all the cell data (select all then delete).
J. Save the updated template (remember to use a macro enabled
template format).
Once this is done 'henever the template is opened there 'ill be t'o
macros 6 one 'hich loads our data and the other 'hich formats it.
&f you really 'anted to get your hands dirty 'ith a bit of code editing
you could easily combine these actions into a single macro by copying
7/23/2019 Vimlesh Negi Document
http://slidepdf.com/reader/full/vimlesh-negi-document 30/30
the code produced from C$oad@ataD and inserting it at the beginning of
the code from CFormat@ataD.