You are on page 1of 12

What you learn Become Familiar with Macros and Visual Basic Editor (VBE)

Link Topic Covered What you Learn

Recording a Simple Macro Create a Macro that:


▪ Inserts a new sheet
▪ Expands the first row
▪ Writes "Header Placeholder" in A1 - Increases font size and makes
bold
▪ Removes Gridlines from this new sheet
SpecialCells Record a Macro to Record macros to highlight special cells
Highlight Special Cells ▪ Highlight and color cells with formulas
▪ Place a value in blank cells inside the current range

SummaryData Absolute Versus Relative Understand the difference between Absolute & Relative Recording
Recording Try 1: Absolute recording to find last empty row
Try 2: Relative recording to find last empty row
Try 3: Mix of Absolute & Relative recording to find last empty row
Final Macro: Consolidate data from different tabs into one

Activity Activity: Delete all


Comments in the Active
sheet
Record a Macro to Highlight Special Cells
Create a macro that dynamically fills up the blank cells with "N"
...and dynamically highlights any cells that have formulas (then split this to second macro)

Business Main Actual Budget


Company Unit Unit Red Flag Revenue Revenue Create the Macro
Entity A BU_1 VC_A Y 10,200 10,404 here and test it on
Entity B BU_1 VC_A 12,240 12,485 the data-set below.
Entity C BU_1 VC_A 14,688 14,982
Entity D BU_1 VC_A 19,776 17,978
Entity E BU_2 VC_A Y 10,300 10,506
Entity F BU_2 VC_A 12,360 12,607
Entity G BU_2 VC_A 14,832 15,129
Entity H BU_2 VC_A 17,798 18,154
Entity I BU_3 VC_B Y 10,400 10,608
Entity J BU_3 VC_B 12,730 12,730
Entity K BU_3 VC_B 14,976 15,276
Entity L BU_4 VC_B 20,000 20,400
Entity M BU_4 VC_B 24,000 24,480
Entity N BU_4 VC_B 28,800 29,376
Entity O BU_4 VC_B 34,560 35,251
Entity P BU_5 VC_B 41,472 42,301
Entity Q BU_6 VC_C 49,766 50,762
Entity R BU_6 VC_C Y 10,500 10,710
Entity S BU_6 VC_C 23,731 21,574
Entity T BU_6 VC_C 25,381 25,888
Entity U BU_7 VC_C 30,457 31,066
Entity V BU_7 VC_C Y 10,200 10,404
Entity W BU_7 VC_C 12,240 12,485
Entity X BU_7 VC_C 14,688 14,982
Entity Y BU_8 VC_C Y 10,100 10,302
Entity Z BU_8 VC_C Y 10,300 10,506

Test the Macro on the below data

Business Main Actual Budget


Company Unit Unit Red Flag Revenue Revenue
Entity A BU_1 VC_A 10,200 10,404
Entity B BU_1 VC_A Y 12,240 12,485
Entity C BU_1 VC_A 16,480 14,982
Entity D BU_1 VC_A 19,776 17,978
Entity E BU_2 VC_A 10,300 10,506
Entity F BU_2 VC_A 13,868 12,607
Entity G BU_2 VC_A 14,832 15,129
Entity H BU_2 VC_A Y 19,970 18,154
Entity I BU_3 VC_B 10,400 10,608
Entity J BU_3 VC_B 14,003 12,730
Entity K BU_3 VC_B 16,803 15,276
Entity L BU_4 VC_B Y 22,440 20,400
Entity M BU_4 VC_B 26,928 24,480
Entity N BU_4 VC_B 32,314 29,376
Entity O BU_4 VC_B 34,560 35,251
Entity P BU_5 VC_B 41,472 42,301
Entity Q BU_6 VC_C 49,766 50,762
Entity R BU_6 VC_C 10,500 10,710
Entity S BU_6 VC_C 23,731 21,574
Entity T BU_6 VC_C 25,381 25,888
Entity U BU_7 VC_C 30,457 31,066
Entity V BU_7 VC_C 10,200 10,404
Entity W BU_7 VC_C 12,240 12,485
Entity X BU_7 VC_C 14,688 14,982
Entity Y BU_8 VC_C 10,100 10,302
Entity Z BU_8 VC_C 10,300 10,506
Absolute Versus Relative Recording
Make sure you have values in A4 (Later we learn different methods of ensuring we don't run into problems)
Business Main Actual Budget
Company Unit Unit Red Flag Revenue Revenue
Entity A BU_1 VC_A Y 10,200 10,404
Entity B BU_1 VC_A N 12,240 12,485
Entity C BU_1 VC_A N 14,688 14,982
Entity D BU_1 VC_A N 19,776 17,978
Entity E BU_2 VC_A Y 10,300 10,506
run into problems)
Copy data to Summary Tab

Make sure you have more than one line of data


Business Main Actual Budget Copy this data below
Company Unit Unit Red Flag Revenue Revenue SummaryData
Entity F BU_2 VC_A N 12,360 12,607
Entity G BU_2 VC_A N 14,832 15,129
Entity H BU_2 VC_A N 17,798 18,154
Entity I BU_3 VC_B Y 10,400 10,608
Entity J BU_3 VC_B N 12,730 12,730
Entity K BU_3 VC_B N 14,976 15,276
Entity L BU_4 VC_B N 20,000 20,400
Entity M BU_4 VC_B Y 24,000 24,480
Entity N BU_4 VC_B N 28,800 29,376
Entity O BU_4 VC_B N 34,560 35,251
Entity P BU_5 VC_B Y 41,472 42,301
Entity Q BU_6 VC_C Y 49,766 50,762
Entity R BU_6 VC_C Y 10,500 10,710
Entity S BU_6 VC_C Y 23,731 21,574
a below
a
Copy data to Summary Tab
Make sure you have more than one line of data
Business Main Actual Budget Copy this data below
Company Unit Unit Red Flag Revenue Revenue SummaryData
Entity T BU_6 VC_C N 25,381 25,888
Entity U BU_7 VC_C N 30,457 31,066
Entity V BU_7 VC_C N 10,200 10,404
Entity W BU_7 VC_C Y 12,240 12,485
Entity X BU_7 VC_C N 14,688 14,982
Entity Y BU_8 VC_C N 10,100 10,302
Entity Z BU_8 VC_C N 10,300 10,506
a below
a
Activity: Delete all Comments in the Active sheet
Create a dynamic macro that deletes all comments for the current worksheet
Assign short-cut key "Control Shift D"
Description should be "This macro deletes all the comments on the active sheet"
Test your macro by going to Activity Test tab and pressing Ctrl + shift + D
Steps for macro:
1. Go to Home / Find & Select /
Business Main Actual Budget Go to Special and select
Company Unit Unit Red Flag Revenue Revenue "comments"
Entity A BU_1 VC_A Y 10,200 10,404 2. Right-mouse click and delete
comments
Entity B BU_1 VC_A N 12,240 12,485 3. Stop the macro recorder
Entity C BU_1 VC_A N 14,688 14,982
Entity D BU_1 VC_A N 19,776 17,978
Entity E BU_2 VC_A Y 10,300 10,506
Entity F BU_2 VC_A Y 12,360 12,607
Entity G BU_2 VC_A Y 14,832 15,129
Entity H BU_2 VC_A Y 17,798 18,154
Entity I BU_3 VC_B Y 10,400 10,608
Entity J BU_3 VC_B Y 12,730 12,730
for macro:
to Home / Find & Select /
Special and select
ments"
ht-mouse click and delete
ents
p the macro recorder
Run the macro you recorded here and make sure all comments are deleted

There is a comment here


and one here

another here

make sure all comments are removed

You might also like