VBA class module--Create TABLE Class (1)

Source: Internet
Author: User

VBA development contact for two months, since the thought of the novice, encountered a lot of problems, but also some experience. According to the problems encountered in the development began to summarize. During the development process, there is a lot of temporary data stored in the process of running the program, which is only used for the next calculation and does not need to be rendered in the final result. The table class module was created for ease of use and management in later steps. class module: CTable
1 Option Explicit2 3 '====================================4 'Name: CTable5 'function: Describe an Excel table area6 '====================================7 8  PublicStrName as String            'Table name9  PublicStraddress as String         'AddressTen  PublicRngstart asRange'Start Cell One  PublicRngend asRange'End Cell A  PublicIcolumns as String           'Number of columns

class module Name: CTable, the following public is the property of the class, this class seems to be no different from the custom type, yes, this is already a class module.

Normal module: Data
Option Explicit'============================'Name: CreateTable'function: Create a table'parameter: strtablename: Table name'astrcolumnnames: Column an array group'return: Table'============================FunctionCreateTable (ByRefstrTableName as String, Astrcolumnnames asVariant) asCTableDimClsstutab as NewCTable'declaring and creating an objectClsstutab.straddress ="sheet2! $A $"    SetClsstutab.rngstart =Range (clsstutab.straddress) clsstutab.strname=strTableNameDimI, J withClsstutab.rngstart. Offset (0,0). Value =Clsstutab.strname J=0         fori =LBound(Astrcolumnnames) to UBound(Astrcolumnnames). Offset (1, j). Value =Astrcolumnnames (i) J= j +1        NextClsstutab.icolumns=JSetClsstutab.rngend =. Offset (1, J-1)    End  withClsStuTab.rngStart.Offset (0,1). Value =clsStuTab.rngEnd.AddressSetCreateTable =ClsstutabEnd FunctionSubCreate student table ()DimClsstudenttable asCTable'declaring an object    DimAstrcolumnnames asVariant astrcolumnnames= Array ("ID","Name","Gender","Stuid","Class")    SetClsstudenttable = CreateTable ("Student Table", Astrcolumnnames)End Sub

Operation Result:

VBA class module--Create TABLE Class (1)

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.