Recent blog postsNavigation |
bookNumeric expressions are what I normally think of when I use the generic term "expression." Whether it's calculating gross margin, figuring out commissions, or determining the monthly payment on a loan, many expressions perform some kind of number crunching. You saw VBA's arithmetic operators earlier in this chapter. This section adds to that by giving you a quick look at VBA's built-in math and financial functions. VBA's Math Functions You'll often use simple expressions that contain just two values and a single operator. In practice, however, many expressions you use will have a number of values and operators. In these more complex expressions, the order in which the calculations are performed becomes crucial. For example, consider the expression 3+5^2. If you calculate from left to right, the answer you get is 64 (3+5 equals 8 and 8^2 equals 64). However, if you perform the exponentiation first and then the addition, the result is 28 (5^2 equals 25 and 3+25 equals 28). The Assignment Operator For example, consider the following code fragment:
A comment is descriptive text embedded within your code. The text of a comment is completely ignored by VBA. It’s a good idea to use comments liberally to describe what you’re doing. You can use a complete line for your comment, or you can insert a comment after an instruction on the same line. A comment is indicated by an apostrophe. VBA ignores any text that follows an apostrophe—except when the apostrophe is contained within quotation marks—up until the end of the line. For example, the following statement does not contain a comment, even though it has an apostrophe: Variables Declaring a Variable
Here String is the Data Type of the variable, which tell what kind of data to store in the variable. Here we have used String which means that myVar will be used to store characters. Assigning value to a Variable myVar = "Ravi Sagar"We will briefly discuss the basic Programming constructs used in the VBA Programming Programming. Any VBA code is build up using these constructs. You can say that these are the building blocks of the Macro. A procedure holds a group of VBA statements that accomplishes a desired Task. A procedure is a series of VBA statements that resides in a VBA module, which you access in the VBE. A module can hold any number of procedures. You have a number of ways to call, or execute, procedures. A procedure is executed from beginning to end (but it can also be ended prematurely). Yeah it is compulsory to have a Hello World! Program in all the Programming Books. So here it is. 1. Create a new Module as explained earlier. Sub Hello_World() MsgBox "Hello VBA World!" End Sub Run this Macro and be amazed. 1. Go back to the Excel Sheet |
Recent comments
14 weeks 6 days ago