Michael Alexander - Excel 2019 Power Programming with VBA

Здесь есть возможность читать онлайн «Michael Alexander - Excel 2019 Power Programming with VBA» — ознакомительный отрывок электронной книги совершенно бесплатно, а после прочтения отрывка купить полную версию. В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: unrecognised, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Excel 2019 Power Programming with VBA: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Excel 2019 Power Programming with VBA»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Maximize your Excel experience with VBA
Excel 2019 Power Programming with VBA Understanding how to leverage VBA to improve your Excel programming skills can enhance the quality of deliverables that you produce—and can help you take your career to the next level.
Explore fully updated content that offers comprehensive coverage through over 900 pages of tips, tricks, and techniques Leverage templates and worksheets that put your new knowledge in action, and reinforce the skills introduced in the text Improve your capabilities regarding Excel programming with VBA, unlocking more of your potential in the office
 is a fundamental resource for intermediate to advanced users who want to polish their skills regarding spreadsheet applications using VBA.

Excel 2019 Power Programming with VBA — читать онлайн ознакомительный отрывок

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Excel 2019 Power Programming with VBA», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Rem -- The next statement prompts the user for a filename

The Remkeyword (short for Remark ) is essentially a holdover from older versions of BASIC, and it is included in VBA for the sake of compatibility. Unlike the apostrophe, Remcan be written only at the beginning of a line, not on the same line as another instruction.

The following are a few general tips on making the best use of comments:

Use comments to describe briefly the purpose of each procedure that you write.

Use comments to describe changes you make to a procedure.

Use comments to indicate you're using functions or constructs in an unusual or a nonstandard manner.

Use comments to describe the purpose of variables so that you and other people can decipher otherwise cryptic names.

Use comments to describe workarounds that you develop to overcome Excel bugs or limitations.

Write comments while you code rather than afterward.

When you've completed all coding, take some time to go back and tidy up your comments, removing any comments that are no longer needed and expanding on comments that may be incomplete or a bit too cryptic.

TIP

In some cases, you may want to test a procedure without including a particular instruction or group of instructions. Instead of deleting the instruction, convert it to a comment by inserting an apostrophe at the beginning. VBA then ignores the instruction when the routine is executed. To convert the comment back to an instruction, just delete the apostrophe.

The Visual Basic Editor offers an Edit toolbar containing tools to assist you in editing your code. In particular, there are two handy buttons that enable you to comment and uncomment entire blocks of code at once.

Note that the Edit toolbar isn't displayed by default. To display this toolbar, choose View ⇨ Toolbars ⇨ Edit.

You can select several lines of code at once and then click the Comment Block button on the Edit toolbar to convert the selected lines to comments. The Uncomment Block button converts a group of comments back into uncommented code.

Variables, Data Types, and Constants

VBA's main purpose is to manipulate data. Some data resides in objects, such as worksheet ranges. Other data is stored in variables that you create.

You can think of a variable as a named storage location in your computer's memory. Variables can accommodate a wide variety of data types —from simple Boolean values ( Trueor False) to large, double-precision values (see the following section). You assign a value to a variable by using the equal sign operator (more about this process in the upcoming section “Assignment Statements”).

You make your life easier if you get into the habit of making your variable names as descriptive as possible. VBA does, however, have a few rules regarding variable names.

You can use alphabetic characters, numbers, and some punctuation characters, but the first character must be alphabetic.

VBA doesn't distinguish between case. To make variable names more readable, programmers often use mixed case (for example, InterestRate rather than interestrate).

You can't use spaces or periods. To make variable names more readable, programmers often use the underscore character (Interest_Rate).

You can't embed special type declaration characters (#, $, %, &, or !) in a variable name.

Variable names can be as long as 254 characters—but using such long variable names isn't recommended.

The following list contains some examples of assignment expressions that use various types of variables. The variable names are to the left of the equal sign. Each statement assigns the value to the right of the equal sign to the variable on the left.

x = 1 InterestRate = 0.075 LoanPayoffAmount = 243089.87 DataEntered = False x = x + 1 MyNum = YourNum * 1.25 UserName = "Bob Johnson" DateStarted = #12/14/2012#

VBA has many reserved words , which are words that you can't use for variable or procedure names. If you attempt to use one of these words, you get an error message. For example, although the reserved word Nextmight make a very descriptive variable name, the following instruction generates a syntax error:

Next = 132

Unfortunately, syntax error messages aren't always descriptive. If the Auto Syntax Check option is turned on, you get the error Compile error: Expected: variable. If Auto Syntax Check is turned off, attempting to execute this statement results in Compile error: Syntax error. It would be more helpful if the error message were something like Reserved word used as a variable. So, if an instruction produces a strange error message, check the VBA Help system to ensure that your variable name doesn't have a special use in VBA.

Defining data types

VBA makes life easy for programmers because it can automatically handle all the details involved in dealing with data. Some programming languages, however, are strictly typed , which means that the programmer must explicitly define the data type for every variable used.

Data type refers to how data is stored in memory—as integers, real numbers, strings, and so on. Although VBA can take care of data typing automatically, it does so at a cost: slower execution and less efficient use of memory. As a result, letting VBA handle data typing may present problems when you're running large or complex applications. Another advantage of explicitly declaring your variables as a particular data type is that VBA can perform some additional error checking at the compile stage. These errors might otherwise be difficult to locate.

Table 3.1lists VBA's assortment of built-in data types. (Note that you can also define custom data types, which are covered later in this chapter in the section “User-Defined Data Types.”)

TABLE 3.1 VBA Built-in Data Types

Data Type Bytes Used Range of Values
Byte 1 byte 0to 255.
Boolean 2 bytes Trueor False.
Integer 2 bytes –32,768to 32,767.
Long 4 bytes –2,147,483,648to 2,147,483,647.
Single 4 bytes –3.402823E38to –1.401298E-45(for negative values); 1.401298E-45to 3.402823E38(for positive values).
Double 8 bytes –1.79769313486232E308to – 4.94065645841247E-324(negative values); 4.94065645841247E-324to 1.79769313486232E308(for positive values).
Currency 8 bytes –922,337,203,685,477.5808to 922,337,203,685,477.5807.
Decimal 12 bytes +/–79,228,162,514,264,337,593,543, 950,335with no decimal point; +/–7.9228162514264337593543950335with 28 places to the right of the decimal.
Date 8 bytes January 1, 0100 to December 31, 9999.
Object 4 bytes Any object reference.
String(variable length) 10 bytes + string length 0 to approximately 2 billion characters.
String(fixed length) Length of string 1 to approximately 65,400 characters.
Variant(with numbers) 16 bytes Any numeric value up to the range of a double data type. It can also hold special values, such as Empty, Error, Nothing, and Null.
Variant(with characters) 22 bytes + string length 0 to approximately 2 billion.
User-defined Varies Varies by element.

NOTE

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Excel 2019 Power Programming with VBA»

Представляем Вашему вниманию похожие книги на «Excel 2019 Power Programming with VBA» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Michael Alexander - Confessions of a Male Nurse
Michael Alexander
Michael Savage - Abuse of Power
Michael Savage
Michael C. Hyter - The Power of Choice
Michael C. Hyter
Elizabeth Power - A Clash with Cannavaro
Elizabeth Power
Michael Alexander Müller - Ein Tropfen in der Zeit
Michael Alexander Müller
Michael Alexander Müller - Aufbruch / Inqilab
Michael Alexander Müller
Michael Alexander Müller - Prinzenpack
Michael Alexander Müller
Michael Carroll - Absolute Power
Michael Carroll
Michael Grant - The Power
Michael Grant
Отзывы о книге «Excel 2019 Power Programming with VBA»

Обсуждение, отзывы о книге «Excel 2019 Power Programming with VBA» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x