Skip to Content
Writing Word Macros, Second Edition
book

Writing Word Macros, Second Edition

by Steven Roman PhD
October 1999
Beginner
410 pages
10h 45m
English
O'Reilly Media, Inc.
Content preview from Writing Word Macros, Second Edition

Variables and Data Types

A variable can be thought of as a memory location that can hold values of a specific type. The value in a variable may change during the life of the program—hence the name “variable.”

In VBA, each variable has a specific data type, which indicates which type of data it may hold. For instance, a variable that holds text strings has the data type String and is called a string variable. A variable that holds integers (whole numbers) has the data type Integer and is called an integer variable. For reference, Table 5-1 shows the complete set of VBA data types, along with the amount of memory that they consume and their range of values. (I will discuss a few of the more commonly used data types in a moment.)

Table 5-1. VBA Data Types

Type

Size in Memory

Range of Values

Byte

1 byte

0 to 255

Boolean

2 bytes

True or False

Integer

2 bytes

–32,768 to 32,767

Long (long integer)

4 bytes

–2,147,483,648 to 2,147,483,647

Single (single-precision real)

4 bytes

Approximately –3.4E38 to 3.4E38

Double (double-precision real)

8 bytes

Approximately –1.8E308 to 4.9E324

Currency (scaled integer)

8 bytes

Approximately –922,337,203,685,477.5808 to 922,337,203,685,477.5807

Date

8 bytes

1/1/100 to 12/31/9999

Object

4 bytes

Any Object reference

String

Variable length: 10 bytes + string length; fixed length: string length

Variable length: <= about 2 billion (65,400 for Win 3.1); fixed length: up to 65,400

Variant

16 bytes for numbers 22 bytes + string ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Word 2013 Bible

Word 2013 Bible

Lisa A. Bucki
Word Annoyances

Word Annoyances

Guy Hart-Davis
Word 2013 on Demand

Word 2013 on Demand

Steve Johnson, Perspection Inc

Publisher Resources

ISBN: 9781565927254Catalog PageErrata