Declaring variable types inside a multidimensional arrays

roscoe

Well-known Member
Joined
Jun 4, 2002
Messages
1,062
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I can't seem to find this anywhere, but, let's say I have an array that looks like Timeline(1 to 100, 1 to 3) where the first dimension are dates and the second dimension are strings.

I'm finding that if I look at the contents of "Timeline" in the watch window some show as dates and others shows as numbers (i.e. 40667.xxxx). I'm thinking if I declare the first dimension as type Date then maybe they'll all look like dates (important for debugging purposes).

Is this true? If so, how do I declare an array with different variable types. Note that I'll use "ReDim preserve" on this array at least once (if that matters).

Thanks!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You cannot specify different types for different dimensions of an array. I suspect the issue may be in how you populate the array - you could use CDate on whatever data you add in order to force date conversion?
 
Upvote 0
... how do I declare an array with different variable types. Note that I'll use "ReDim preserve" on this array at least once (if that matters).

To have an array with different data types you'd have to declare a user data type, in your case with a Date and a String.

I think Rory's suggestion is simpler and solves your problem, but if you want to try a user type solution, here's an example:


Code:
Option Explicit
 
Type utTimeLine
    dt As Date
    s As String
End Type

Sub test()
Dim TML() As utTimeLine
 
ReDim TML(1 To 1)
TML(1).dt = DateValue("2011-05-16")
TML(1).s = "Today"
 
ReDim Preserve TML(1 To 2)
TML(2).dt = TML(1).dt + 1
TML(2).s = "Tomorrow"
 
MsgBox _
    "TML(1) dt: " & TML(1).dt & " , s: " & TML(1).s & vbNewLine & _
    "TML(2) dt: " & TML(2).dt & " , s: " & TML(2).s
End Sub
 
Upvote 0
Thanks to you both. I think I'll try cDate first.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top