How to Create a Default Value in Excel

Posted In Excel Tips, Microsoft Office - By Piyush Dungrani On Saturday, January 22nd, 2011 With 0 Comments

When you want to input a lot of data very quickly it helps to be prompted with defaults. For example if you are adding lots of records for the same company it would slow you down to have to keep typing out the whole thing over and over. Even better, if most of your records are identical other than some minor differences you can give yourself a head start by pre-populating most of the required data.

Excel+Cell+Drag+Disabled+or+Not+Wokring+ +Solution How to Create a Default Value in Excel

It will be much clearer when we go through an example. Picture a system where we have to enter address details but 99% of our addresses will be for people living in the USA. We will make the spreadsheet populate the country so we can focus on the country only in the rare non-USA exceptions.

usa exceptions How to Create a Default Value in Excel

Once we have entered our address data we can have a macro that populates the Country cells

country cells How to Create a Default Value in Excel

In this case we will go with a button which when pressed will fill in the cells, but obviously there are other options available.

default How to Create a Default Value in Excel

Draw a button and the user will know what to do when they want to complete the form. Filling out these cells when the button is clicked is really simple.

really simple How to Create a Default Value in Excel

Just assign the following macro to the button in the dialog that appears and you are good to go.

good to go How to Create a Default Value in Excel

Automatically Filling Cells without a Button

What if you don’t want the user to have to click? Can we automatically fill any blank cells? What would be neat is if the spreadsheet would automatically enter USA whenever we erase the contents of a cell. This way an empty cell will always revert to the “USA” value.

Well we can do this using the Microsoft Excel events system.

events system How to Create a Default Value in Excel

Excel provides us with a Worksheet_Change event. Any code we enter into this Sub routine will execute as the user enters data. Pretty cool, huh?

There is a danger though with altering the spreadsheet data using such an event. A possibility exists where the spreadsheet changes and changes in a never ending loop, because every time you change the spreadsheet then Excel will notice the change and fire up the change event all over again!

So to avoid this unfortunate potential we can turn off the event while we do our thing, we use Application.EnableEvents = False to switch it off, then of course remember to set it back to True when we are done to turn it back on again.

Summary

Obviously we kept the example simple for the sake of clarity but I am sure you can imagine scenarios where being able to “guess” the required data and pre-populate using defaults would save your users a great deal of time. How might you use this in your projects?

About the author

Yoav Ezer co-authors the technology and productivity blog Codswallop. He is also the CEO of a company that produces PDF to Excel conversion software.

For more Excel tips from Yoav, join him on Facebook or Twitter

Incoming search terms:

Excel default value, excel 2010 default value, default value in excel, default value excel 2010, excel cell default value, default value excel, how to set default value in excel 2010, default cell value in excel, excel 2010 table default values, how to set default value in excel, how to pre-populate a cell in excel with a value, how to provide a default value excel, how to set automatic value in excel, how to pre-populate cells in excel2010, how to set a default value in excel cell

About - A techie by profession (software engineer) and a part time blogger by choice with immense knowledge of SEO, also writes articles on Google, Microsoft, Apple, iPhone, Internet, Blogger, Social Media and windows. Catch him on Twitter, Join Facebook Fan Page. Subscribe to GeekBlogger feed via RSS or EMAIL to receive instant updates.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>