Quora Excel Genius Compendium
Quora Excel Genius Compendium
Try this:
1. Select the cells you want to enter mobile phone
numbers in.
Now you can enter mobile phone numbers, *without*
2. Display the Format Cells dialog (the short cut key is entering the "+91" prefix.
CTRL+1)
That is, simply enter "123456789" rather than
3. From the numbers tab, select "Custom" in the "+91123456789".
Category list. Give it a try !
4. In the box called "Type:" enter this custom number
format: +91000000000
5. Click OK
VBA Yes, you can write your own functions in Excel VBA.
These can be used like a regular worksheet function or by
Question
other VBA code to perform specific calculations.
How can you write or Here’s an example . . .
create your own
functions in Excel VBA? Let’s pull it apart . . .
1. In this example, we’ve added a constant for Pi (3.142).
This is not necessary, but I just wanted to demonstrate
that your functions can also reference other values to
perform its calculation - even other functions.
2. This is the name of your function as well as any
This example has a function called coneVolume which information your function needs to perform its
calculates the volume of ice-cream cones (or any other cones calculation. These are called parameters. Notice that
for that matter) given the cone’s radius and height. each parameter has a name and a date type. (Tip:
It looks like any standard formula using a Excel worksheet What you pass to these parameters are called
function. “arguments”)
It starts with an equal sign, then the name of the function 3. This next piece may - or may not - be relevant to your
and parameter values (if any) between parenthesis. needs. Application.Volatile tells Excel to recalculate
your function every time any cell in your worksheet
When you write a function in VBA it’s called a User Defined recalculates.
Function, or UDF for short.
4. If you want your function to recalculate only when
Let’s take a look and the nuts-and-bolts of the coneVolume
inputs (parameters) to your function change, then
function in VBA, shall we?
leave this line out.
The square brackets means this argument (or input) is When VLOOKUP finds the value you’re looking for, you want
optional. You don’t have to provide a value if you don’t want. it to get a related value in that same table.
But if you don’t, Excel assumes what the value will be (more This arguments is asking which column has the value you
about this in this in a minute). want in the range it’s searching.
Rather than the cryptic argument names in the image above, 4) how precise?
let’s change the wording of these arguments to something VLOOKUP gives you the option of searching for an exact
more friendly and discuss each one. match or an approximate match.
The VLOOKUP formulas says: “Go and find 6,500 in the range
B3:C6 and where 6,500 does not exceed the Sale value bring
back what’s in the second column.”
In this example, VLOOKUP would bring back 5% as 6,500 is
more than 5,000 but less than 10,000.
In cell G4 you can see our VLOOKUP function.
The VLOOKUP formulas says: “Go and find ‘Goofy’ in the
range B3:D6 and bring back what’s in the third (3) column
and I don’t want (that is, FALSE) an approximate match.”
In this example, VLOOKUP would return 24.
If VLOOKUP could not find Goofy in the list, it would return
#N/A.
LOOKUP with an Approximate Match
So when would you want to use an approximate match?
If that's the case, then I've got some bad news and something
else resembling good news
VBA’s Visual Basic Editor (a.k.a. the VBE) doesn’t have a
theme option.
But it does have some (basic) capability to change the colours You’ll need to select the Code Colors one at a time and
of the module and code within a module. change the Foreground, Background and Indicator colour for
Here’s a (rather ugly) example . . . each code colour.
A little tedious, I know, and you’ll probably need to
experiment a little to get the “look” you’re after.
I’m not aware of any means to automate this or save (and
reapply) the settings.
Let’s change the colours so it look like the proper VBA code in
Excel’s Visual Basic Editor screenshot above.
1. If it’s not currently open, open the Visual Basic Editor
and display the Options screens. In the VBA Editor,
from the Tools menu, select Options and then select
the Editor Format tab. The whole process is a little tedious, I know, and you’ll
probably need to experiment a little to get the “look” you’re
2. In the list of Code Colors, select ‘Normal Text’.
after.
3. From the Foreground dropdown list, select ‘Yellow’.
4. From the Background dropdown list select ‘Black’.
It’s intuitive.
It’s really easy to use.
Darn, if you can use a calculator you can . .
. . oh.
Okay, silliness aside, with a 34 year heritage, Excel is about as
intuitive and easy (yet incredibly powerful) a spreadsheet
application you’ll find.
While cell I3 has a salary value for Minnie, you can see we Your VLOOKUP would now look like this:
have more than one Minnie in our list. We also have several
employees with common first or last names.
But the way VLOOKUP works, it will retrieve the first
matching item in our list.
Here’s one way to work around this.
Create a Unique ‘Key’
You aim to create a value that is unique in your list. A ‘unique
identifier’ or ‘key’.
In this example, you could try a combination of ‘First Name’
and ‘Last Name’.
Here’s how it might work . . .
This example doesn’t have the ability to sort or filter the list
of worksheets, but that could easily be added.
There’s probably quite a few other ways you could add
navigation to a workbook with many worksheets (custom
ribbon tab perhaps?) but these suggestions may provide
some ideas.
Pink or Blue?
Chocolate or Vanilla?
Less than 3.142 or more than Pi?
If you need to make any decisions in your process (code), the
macro recorder can't help you make them. But the macro recorder can't do this.
VBA has several ways to branch logic (make decisions) such I hate to sound like a broken record (okay I am repeating
as the IF statement (let's not forget IIF) and SELECT CASE: myself), but if you want any task performed multiple times
(without repeating the code) you're going to have to write
those loops yourself.
The Macro Recorder Can't Message You
Sometimes you'll want to prompt the person using your
spreadsheet (that person might be you).
That prompt might be a confirmation that a process has
But none of these can be recorded. finished:
You'll need to write them manually yourself.
The Macro Recorder Can't Repeat Itself
Sometimes the task you want to do is pretty simple.
Maybe copy some cells from one location to another. Maybe
you need to perform (repeat) this across multiple
worksheets.
What? No UserForms? You’d be surprised what you can achieve via Automation.
One way your Excel applications can interact with its users is For example, you could have an Excel application “tell”
via a screen or UserForm. Microsoft Word to create an invoice using values in an Excel
spreadsheet and then attach the invoice to an email in
Here’s an example: Outlook.
You’ve probably already guessed by now, and you’d be right -
automating one application from another cannot be done
using the macro recorder.
To make all the Microsoft Office application sing-and-dance
together, you’ll need to write the VBA code yourself.
Formulas Cells If however, you do actually have cells with zero that you
want to exclude from the average calculation, then Salam is
If you only want to exclude blank cells from your average,
Question correct; the AVERAGEIF function is what you need.
there is no need to use the AVERAGEIF function.
What is the excel formula Here’s an example:
The AVERAGE function will already ignore blank cells for you.
to calculate average value Average with Blank Cells
ignoring blank cells? Here’s an example:
Side Note
One other responder
stated you must use
AVERAGEIF which is why I
mention it in my answer. Again, I’ve included the formula in row 10 so you can see
what’s going on.
As you can see, it’s not
The first part of the AVERAGEIF function – here C18:C22 –
necessary to ignore The cell with the red border has a zero. As you can see, it is
tells Excel which range of cells you want to test.
blanks (but is necessary included in the Average calculation.
In the next argument – here “<>0” – you tell Excel what your
to ignore zeroes). Meanwhile, the cell with the green border is blank. Excel
test condition is. Here’s we’ve told Excel we want to
ignores this cell and gives us the correct (or at least expected)
calculate the average where the values do not equal zero.
average of 10.
Finally, the last argument – here also C18:C22 – we tell Excel
I’ve included the actual formulas in row 10 so you can see
which cells we want to know the average of.
how the averages were calculated.
As you can see, AVERAGEIF correctly excludes the zero value.
As you can see, a blank cell has no impact on Excel’s
AVERAGE function.
In this example, you call the function and assign the resulting
range object to a variable called Target. You can then decide
what you want to do with this range.
Format it.
Delete it.
Whatever.
But this function does have a few limitations <gasp!>. Okie dokie, now we’re cooking. GetRows Mark II, addresses
some of the limitations of the first version :)
For example, what if your range does not have a heading row
as this one assumes? The first thing we’ve added is a flag called HasHeading.
Or what if you wanted to delete every third row, or every This lets you tell the function if the range has a heading row.
seventh row. If it does have a heading, the looping will start from row 2,
otherwise it will start from row 1. Neato :)
This function won’t help either. Let’s see if we can improve it
a little . . .
You’ll find the option to do this under the Review tab on the
Excel Ribbon:
Check it out.
Simply open the workbook you want to protect and click the
Protect Workbook button.
You’ll be presented with a small screen asking for a
password:
The second line deletes the actual sheet that was just
inserted.
The last line tells Excel to start prompting you again for
actions such as deleting things.
Finally, from the Home ribbon tab, click the Close & Load
button.
Voila!
You have your data in your spreadsheet.
VBA Workbooks with VBA? 1. First find and select the UserForm you want to
There’s 3 main techniques you can use to transfer a transfer.
Question 2. Right-click your mouse and from the short-cut menu
UserForm from one workbook to another.
How do I transfer You can use: select Export File
userform(UI) from one 1. Drag-and-Drop, 3. Choose a suitable folder to save the UserForm
workbook to another in 4. Now select the destination workbook.
2. Export / Import and
VBA? 5. Right-click your mouse and choose Import File.
3. VBA Automation.
Let’s look at each :) 6. Select the saved UserForm and click Open
Drag-and-Drop Method VBA Automation Method
The first technique is the easiest. You can drag the UserForm The third technique – and the one I believe you really want to
your want from one workbook to another in the Visual Basic know about – uses VBA to automate the process of
Editor (VBE). transferring a UserForm.
1. First find and select the UserForm you want to The first thing you’ll need to do for this – before you write
transfer. any code, is set a reference to the Microsoft Visual Basic for
Applications Extensibility library.
2. Hold down the left mouse button
In the VBA Editor, from the Tools menu, choose References:
3. Drag the UserForm to the destination workbook, and
4. Release your mouse button.
Export / Import Method
While the second technique has more steps, it does provide
you a backup copy of just the form without the workbook.
This might be handy if you want to email the form to
someone with giving them the entire workbook.
Excel Tables Genius Page | 66
My Excel Genius
Scroll down the list and tick (check) the Microsoft Visual Basic
for Applications Extensibility library 5.3.
So, what’s this for?
This gives you access to the object hierarchy of the VBE so
you can manipulate objects like modules, classes and, of
course UserForms.
Rather than describe each step, here’s some sample code
with comments.
Since 2007, Excel hasn’t supported creating floating toolbars Note that Picture Boxes don’t respond to “click” (the click
or buttons in the same way. event) so you can use the MouseUp event instead like this:
So, the short answer is no, you can’t create a floating toolbar
or floating buttons the way you used to be able to in Excel.
However, Excel is a flexible beast and there’s usually more
than one way to achieve a result. You mentioned that you wanted to add the floating buttons
to a workbook. I take it you want these buttons available to a
From your question it sounds like you only want this floating specific workbook.
button to be available for a specific workbook.
So assuming you have created the UserForm floating toolbar
Let’s take a look at how you can do that. in the appropriate workbook you can get it to display each
First the “toolbar” or “floating button” in this case. time the workbook opens like this:
This is going to take a little VBA and the magic of a UserForm.
In Excel’s Visual Basic Editor you can create a form (known in
Excel as a UserForm) which can hold controls.
In your case you want a button. You can add a button, but
I’ve got to confess, they’re kinda ugly.
WELCOME
Hello and welcome to My Excel Genius. Automation
Chances are you’re browsing this compendium Learn VBA macros to automate the boring
because you use Excel in your job. A lot! stuff, save yourself a shedload of time and
dramatically increase your income and
Alternatively, you have some niggling business
promotion potential.
problem which is costing you time, money & stress.
If you must get faster and smarter results in Excel (and It’s all about Data
Marcus Syben
let’s face it – who doesn’t), you’re in the right place.
Learn the right tools to manage and analyze
Learning from the Experience of Others data like you job depends on it (because it
does).
If you use Excel in your business or in your job, I hope you
found some useful ideas in this compendium. Exploring how Functions
others solved problems you’re facing is a great way of
expanding your repertoire. Excel has almost 500 worksheet function.
Learn the ‘right’ 5% of functions you need to
The Big 4 Excel Skills you Need achieve 95% of the results.
If you want to develop your Excel skills to accelerate your
career or get more done in your business, here’s where you Where to from Here?
should focus your attention . . .
If you would like to learn more about how Excel can advance
Keyboard Shortcuts your career or solve your business problems, click the email
link below to drop me a line. Let’s talk . . .
Just like a touch-typist will outperform a
two-fingered typist, you will save a huge [email protected]
ridiculous amount of time learning keyboard
shortcuts to get more done faster.
Excel Tables Genius
Copyright © 2021 My Excel Genius