Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8526293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:13:52+00:00 2026-06-11T08:13:52+00:00

I am trying to create a custom data type in VBA for Excel. Let’s

  • 0

I am trying to create a custom data type in VBA for Excel. Let’s call this data type “truck”. Each truck has the following attributes:

NumberOfAxles (this is an integer)
AxleWeights (this is an array of doubles)
AxleSpacings (this is an array of doubles)

Can I create many instances of the data type “truck” (truck(1), truck(2)… etc), and read/write the attributes I listed above to that instance?

Example:

Truck(1).NumberOfAxles = 2
Truck(1).AxleWeights(1) = 15.0
Truck(1).AxleWeights(2) = 30.0
Truck(1).AxleSpacings(1) = 8.0

Truck(2).NumberOfAxles = 3
Truck(2).AxleWeights(1) = 8.0
Truck(2).AxleWeights(2) = 10.0
Truck(2).AxleWeights(3) = 12.0
Truck(2).AxleSpacings(1) = 20.0
Truck(2).AxleSpacings(2) = 4.0

and so on. The syntax above is most possibly wrong, I just wanted to demonstrate the structure I need to come up with.

All I am trying to write data to a data structure and call it as necessary such as

Truck(i).NumberOfAxles
Truck(i).AxleWeights(j)
Truck(i).AxleSpacings(j)

Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:13:54+00:00Added an answer on June 11, 2026 at 8:13 am

    Sure you can:

    Option Explicit
    
    '***** User defined type
    Public Type MyType
         MyInt As Integer
         MyString As String
         MyDoubleArr(2) As Double
    End Type
    
    '***** Testing MyType as single variable
    Public Sub MyFirstSub()
        Dim MyVar As MyType
    
        MyVar.MyInt = 2
        MyVar.MyString = "cool"
        MyVar.MyDoubleArr(0) = 1
        MyVar.MyDoubleArr(1) = 2
        MyVar.MyDoubleArr(2) = 3
    
        Debug.Print "MyVar: " & MyVar.MyInt & " " & MyVar.MyString & " " & MyVar.MyDoubleArr(0) & " " & MyVar.MyDoubleArr(1) & " " & MyVar.MyDoubleArr(2)
    End Sub
    
    '***** Testing MyType as an array
    Public Sub MySecondSub()
        Dim MyArr(2) As MyType
        Dim i As Integer
    
        MyArr(0).MyInt = 31
        MyArr(0).MyString = "VBA"
        MyArr(0).MyDoubleArr(0) = 1
        MyArr(0).MyDoubleArr(1) = 2
        MyArr(0).MyDoubleArr(2) = 3
        MyArr(1).MyInt = 32
        MyArr(1).MyString = "is"
        MyArr(1).MyDoubleArr(0) = 11
        MyArr(1).MyDoubleArr(1) = 22
        MyArr(1).MyDoubleArr(2) = 33
        MyArr(2).MyInt = 33
        MyArr(2).MyString = "cool"
        MyArr(2).MyDoubleArr(0) = 111
        MyArr(2).MyDoubleArr(1) = 222
        MyArr(2).MyDoubleArr(2) = 333
    
        For i = LBound(MyArr) To UBound(MyArr)
            Debug.Print "MyArr: " & MyArr(i).MyString & " " & MyArr(i).MyInt & " " & MyArr(i).MyDoubleArr(0) & " " & MyArr(i).MyDoubleArr(1) & " " & MyArr(i).MyDoubleArr(2)
        Next
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The task: I am trying to create a custom data type and have it
What I'm trying to do is create a new custom data type that behaves
I am trying to create a custom User library in CodeIgniter. Inside this library
I am trying to create a custom field type which will display values based
What I'm trying to do is to create a custom type, with a custom
I'm trying to create a custom field type with jQuery autocomplete functionality. But I'm
Im trying to create a custom version of the RequiredAttribute to replace the built
I'm trying to create a custom TabItem that is dynamically added to a TabControl
I'm trying to create a custom SELECT query to find my Personal Best races
I'm trying to create a custom form input that utilizes some images, it should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.