[C001] Excel VBA-Custom Data Type

Source: Internet
Author: User

Source: http://blog.csdn.net/alexbnlee/article/details/6923787

→ The Type statement is required for custom data types.

Type lianxiren    name As String    sex As String    age As Integer    phone As String    address As String    department As StringEnd TypeSub AddressList()    Dim record As lianxiren    record.name = "Alex"    record.sex = "Male"    record.age = 23    record.phone = "18812345678"    record.address = "Blahblah"    record.department = "Blahblah"    MsgBox record.nameEnd Sub

A custom data type is created before, and can be referenced later.

→ A system constant is a constant defined in the VBA system. It generally starts with a prefix of Vb.
For example, VbRed and VbOKOnly ~

→ Object data indicates the reference of an Object. The stored content is the address of an Object. When an Object variable is assigned a value, the copy statement cannot be used directly, instead, the Set statement should be used to assign values to it.
Dim Sheet As Object
Set Sheet = Worksheets ("sheet1 ")

→Is compares whether two Object variables are applied to the same variable. If the same variable Is used, True Is returned; otherwise, False Is returned.

→ Like example (similar to replacement in Word)

Dim MyCheckMyCheck = "aBBBa" Like "a * a" 'returns True. MyCheck = "F" Like "[A-Z]" 'returns True. MyCheck = "F" Like "[! A-Z] "'returns False. MyCheck = "a2a" Like "a # a" 'returns True. MyCheck = "aM5b" Like "a [L-P] # [! C-e] "'returns True. MyCheck = "BAT123khg" Like "B? T * "'returns True. MyCheck = "CAT123khg" Like "B? T * "'returns False.

→ Pause statement, Stop statement, the statement will Stop at the Stop position, and then press run to continue running... A semicolon can also be used to connect strings, and spaces are added to the left and right sides of numbers.

Sub Stop1 () Dim I As Integer For I = 1 To 5 Debug. Print "program No."; I; "pause" Stop NextEnd Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.