General Format of Thesis Journal

Topics: C, Assignment, Equals sign Pages: 34 (3731 words) Published: February 25, 2014
Essential Elements of VBA
Language


Using Comments in VBA Code



Using Assignment Statements



Sub FormatCells()
‘ Exit if a range is not selected
If TypeName(Selection) “Range” Then
MsgBox “Select a range.”
Exit Sub
End If
‘ Format the cells
With Selection
.HorizontalAlignment = xlRight
.WrapText = False ‘ no wrap
.MergeCells = False ‘ no merged cells
End With
End Sub

Using Variables, Constants, and
Data Types



Since VBA is a real, live programming language, it utilizes various elements common to all programming languages. Comment is the simplest type of VBA statement. Apostrophe (‘) is used to start a comment. Comments can be inserted at the end of a line of code or you use the entire line for your comment. See example below:

Arrays
*Property of STI

I0033

1 __________________________ 2 _________________________
____________________________ ___________________________
____________________________ ___________________________
____________________________ ___________________________
____________________________ ___________________________
____________________________ ___________________________
____________________________ ___________________________
____________________________ ___________________________
____________________________ ___________________________

VBA does not interpret an apostrophe inside a set of quotation marks as a comment indicator. The example below illustrates this
condition, though there is an apostrophe:

Edit Toolbar under the View Menu

Msg = “Can’t continue”

VBA will ignore statements starting with apostrophes when a routine is executed. Simply remove the apostrophes to make those
statements active again. The quick way to convert a series of statements to comments in VBE is to select View > Toolbars > Edit to show the Edit Toolbar. Select the statements and click the
Comment Block button to convert the series of statements into comments. Select the statements and click the Uncomment Block button to remove the apostrophes. See Figures on the next page: *Property of STI

I0033

Edit Toolbar

*Property of STI

I0033

3 __________________________ 4 _________________________
____________________________ ___________________________
____________________________ ___________________________
____________________________ ___________________________
____________________________ ___________________________
____________________________ ___________________________
____________________________ ___________________________
____________________________ ___________________________
____________________________ ___________________________

The tips below can help create effective and useful comments: • Recognize yourself as an author.
• Describe the purpose of each Sub and Function procedure
briefly.
• When making changes to a procedure, use comments to track the changes.
• Use comment to indicate that you are using a function or a construct in an unusual or nonstandard manner.
• When not using meaningful variable names, use comments to describe the variables you use.
• To overcome bugs in Excel, use a comment to describe any workarounds you develop.
• Instead of saving the task for a final step, write comments as you develop code.
*Property of STI

I0033



Understanding variables
The main purpose of using VBA is to manipulate data. Certain data, like worksheet ranges, resides in objects. Some data is stored in variables you have created. A variable is a named
storage location in the computer’s memory which is used by a program. A value is assigned to a variable using the equal sign (=) operator. In the example below, the variable names appear on both the left and right sides of the equal signs. See examples below:

x = 1
InterestRate = 0.075
LoanPayoffAmount = 243089
DataEntered = False
x = x + 1
UserName = “Bob Johnson”
Date_Started = #3/14/2013#
MyNum = YourNum * 1.25

*Property of STI

I0033...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • THESIS FORMAT Essay
  • Thesis Format Essay
  • Thesis Documentation Format Essay
  • Thesis Paper Format
  • Sample Thesis Format Essay
  • Additional Information for Thesis Format Essay
  • thesis Essay
  • Thesis Essay

Become a StudyMode Member

Sign Up - It's Free