Sponsored Link

Sponsored Link

Monday, December 22, 2008

MS Excel, Macro & VBA e-books download

I wish to post all the E-books available on this earth on my blog. However, it is not practical to do so. I would request you to subscribe to blog via email to receive e-books and updates. As you subscribe, it becomes easier for me to send everyone at one go. I find the MS Excel help as the best help. Also, you can find lot of 'How to' on MS Excel Office web site.


Kindly do let me know your comments about his post.

Read more on this article...

Tuesday, December 16, 2008

Understanding Visual Basic Editor in MS Excel

There are three main components that one should understand about Visual Basic Editor in MS Excel viz., Project Explorer, Properties and code window. All the version of MS Excel has same shortcut keys Alt + F11 key to bring up Visual Basic Editor in MS Excel. The picture shown below is Visual Basic Editor.

Click here to view enlarge

Microsoft Excel, VBE

Standard toolbar

Like any other Microsoft tool it comes along with ribbon toolbars. Shown below in the picture is standard toolbar which help you in performing various functions like run code, pause code and stop code which we will learn in details.

Click here to view enlarge

standard toolbar

Properties Window
Each object used in MS Excel has certain properties. These properties can be viewed in Properties window. We shall use these properties in examples ahead. In the picture below the properties window is showing the properties of sheet1. In case if you don’t find the properties window in VBE than press F4 key. F4 is shortcut key for bringing up Properties Window.

Properties are like the way you want the object to behave. Sometimes propertries are change on the runtime(While code is running). However, you can change all the properties at runtime

Click here to view enlarge

properties window

Project Explorer
Project Explorer shows all the Sheets, modules and classes presents in the project. Used of Project Explorer will be shown in the next post.

Click here to view enlarge

Microsoft Excel, Project Explorer

Code Window

Code windows is where you write your macro/VBA code. Code window has two drop downs one with the list of object as per the container selected in the project explorer. Like if Sheet1 is selected in the project explorer than you will find worksheet in left handside drop down. If the ThisWorkbook is selected then you will find Work in the left handside drop down. Similarly, you will find possible events listed in right handside drop down. For workbook you will find events like open, Window activate, Window deactivate etc. For worksheet, you will find events like SelectionChange etc

Click here to view enlarge

code window


Also, to add more to your knowledge about VBE. Visit following website : http://office.microsoft.com/en-us/help/HA010429591033.aspx

Feel free to comments about this post.  Also, you can receive free e-books, Add-ins, updates. Click here to Subscribe

We assure you knowledge, not SPAM!

Read more on this article...

Wednesday, December 10, 2008

VARIABLE Declaration in VBA

This will be shown only in post's page. Variable is used to store temporary information that is used for execution within the Procedure, Module or Workbook. Before we go into some detail of Variables, there are a few important rules that you must know about.

1) A Variable name must Start with a letter and not a number. Numbers can be included within the name, but not as the first character.
2) A Variable name cannot be longer than 250 characters.
3) A Variable name cannot be the same as any one of Excel's key words. By this, I mean you cannot name a Variable with such names as Sheet, Worksheet etc.
4) All Variables must consist of one continuous string of characters only. You can separate words by either capitalising the first letter of each word, or by using the underscore characters if you prefer.

You can name variables with any valid name you wish. For Example you could name a variable "Charles" and then declare it as any one of the data types shown below. However, it is good practice to formalize some sort of naming convention. This way when reading back your code you can tell at a glance what data type the variable is. An example of this could be the system I use! If you were to declare a variable as a Boolean (shown in table below) I may use: bIsOpen I might then use this Boolean variable to check if a Workbook is open or not. The "b" stands for Boolean and the "IsOpen" will remind me that I am checking if something is open.

You may see code that uses letters only as variables, this is bad programming and should be avoided. Trying to read code that has loads of single letters only can (and usually does) cause grief.

Mentioned below are the data types that can be used in VBA

Byte data type
A data type used to hold positive integer numbers ranging from 0 to 255. Byte variables are stored as single, unsigned 8-bit (1-byte) numbers. Useful when you know the maximum value that you want to store the in the variable.
Example below shows how to declare byte variable.

Dim btValue As Byte

Boolean data type
A data type with only two possible values, True (-1) or False (0). Boolean variables are stored as 16-bit (2-byte) numbers. Useful when you want to check certain value return after testing. Also, useful in controlling the program flow and you declare boolean its value is false by default

Dim blTest as boolean

Integer data type
Integer is most commonly used variable. A data type that holds integer variables stored as 2-byte whole numbers in the range -32,768 to 32,767. The Integer data type is also used to represent enumerated values. The percent sign (%) type-declaration character represents an Integer in Visual Basic.

Dim intCount As Integer

Long data type
A 4-byte integer ranging in value from -2,147,483,648 to 2,147,483,647. The ampersand (&) type-declaration character represents a Long in Visual Basic.

Dim lngCount As Long

Currency data type
A data type with a range of -922,337,203,685,477.5808 to 922,337,203,685,477.5807. Use this data type for calculations involving money and for fixed-point calculations where accuracy is particularly important. The at sign (@) type-declaration character represents Currency in Visual Basic.

Dim cur_profit As Currency

Single data type
A data type that stores single-precision floating-point variables as 32-bit (2-byte) floating-point numbers, ranging in value from -3.402823E38 to -1.401298E-45 for negative values, and 1.401298E-45 to 3.402823E38 for positive values. The exclamation point (!) type-declaration character represents a Single in Visual Basic.

Dim sngValue As Single

Double data type
A data type that holds double-precision floating-point numbers as 64-bit numbers in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values. The number sign (#) type-declaration character represents the Double in Visual Basic.

Dim dbValue as Double

Date data type
A data type used to store dates and times as a real number. Date variables are stored as 64-bit (8-byte) numbers. The value to the left of the decimal represents a date, and the value to the right of the decimal represents a time.

Dim dtStart as date

String data type
A data type consisting of a sequence of contiguous characters that represent the characters themselves rather than their numeric values. A String can include letters, numbers, spaces, and punctuation. The String data type can store fixed-length strings ranging in length from 0 to approximately 63K characters and dynamic strings ranging in length from 0 to approximately 2 billion characters. The dollar sign ($) type-declaration character represents a String in Visual Basic.

Dim strName as String

Object data type
A data type that represents any Object reference. Object variables are stored as 32-bit (4-byte) addresses that refer to objects. Variant data type A special data type that can contain numeric, string, or date data as well as the special values Empty and Null. The Variant data type has a numeric storage size of 16 bytes and can contain data up to the range of a Decimal, or a character storage size of 22 bytes (plus string length), and can store any character text. The VarType function defines how the data in a Variant is treated. All variables become Variant data types if not explicitly declared as some other data type.

One small example of variable in macro is written below.

Sub VariableMacrotest()
Dim intEntervalue As Long
'Sheet1.Cells(1, 1) refers to A1 on sheet1
intEntervalue = Sheet1.Cells(1, 1)
MsgBox intEntervalue * intEntervalue
End Sub

To use the above code, press Alt + F11 to open the Visual Basic editor in MS Excel. If you don’t see the project explorer which by default on right hand side. Press Ctrl + R key. You will see the sheet MS Excel Worksheets. Right Click on the VBAProject(Workbookname) and go to insert and click on the module.
Copy past the code in the module and press F5 to run the macro/vba code.

Here I have attempted to put light on variable type available in MS Excel. I am sure this post was helpful. There are few more example I will post on variable in coming days.
Kindly subscribe to our blog via email to receive latest updates, its free.
We assure you knowledge, not SPAM!
Read more on this article...

Wednesday, December 3, 2008

Shortcut to move to Active Cell in Selection

This is the most common practice that I have observed in MS Excel user. If they select the large area on worksheet, they then use mouse to scroll and go back to active cells. The shortest way to go back to Active Cells is by pressing Ctrl Key + Backspace key

This post might not appear valuable to most of you readers. However, remember one thing. By using shortcuts you not only save your time. But exhibits how well you know the MS Excel to others users.

Also, do let me know your comments about this post and subscribe to us to receive latest updates via email

We assure you knowledge, not SPAM!

Read more on this article...

Prevent charts from being printed in MS Excel

Not all the time you want to print charts. Here is any trick prevent charts from being printed. Please follow the steps below. I am sure this will definitely help when you come across such scenario.

  • Select a chart, and right-click on chart. From the right click menu, select Format Chart Area.
  • Click on Properties tab, and remove the check from checkbox which says Print Object.
  • Click OK.

This trick is useful when you want to save your printer toner from preventing graph. If you like this post do let your comments and Subscribe via email

We assure you knowledge, not SPAM!

Read more on this article...

Tuesday, December 2, 2008

VBA advantages

The large portion of work in MS Excel can be achieved via macro and VBA. This post is an attempt to help MS Excel user with VBA. The post below provides an overview about Macro/VBA. In forth coming post I will tell you how to start VBA or in other words a VBA tutorial.

You can automate almost anything you do in Excel. To do so, you will have to write

Instructions that you want Excel to perform. Automating a task by using VBA offers several advantages:

Excel always executes the task in exactly the same way and with more consistency.

VBA performs the task much faster than you can do it manually.

If you’re a good macro programmer, Excel always performs the task without errors.

If you set things up properly, someone who doesn’t know anything about Excel can perform the task.

With MS Excel you can do things which are otherwise looks impossible — Also, it makes you popular in your work place

For long, time-consuming and monotonous tasks, Excel performs the entire task while you enjoy leisure

Under MS Excel help, VBA is little unexplored by most of the users. Everyone knows that’s things are possible using VBA. But, we look for work around. In next month, will post free tutorials based on VBA/Macro.

I hope you will like this post. Please express your view about this post via comments.

Also, you can subscribe to this post via email

We assure you knowledge, not SPAM!

Read more on this article...