What does this vba mean????

MsAlitaY

New Member
Joined
Jul 19, 2016
Messages
4
What does Dim DC() mean? I'm used to only seeing "Dim as" whatever.

What does this code do?

Dim DC()
ReDim DC(LCol - 6)

For i = 0 To LCol - 6
DC(i) = i + 6
Next
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Dim DC() is the same as writing Dim DC() as Variant
It is declaring DC as a variant array and the next line is then setting the size of that array
 
Upvote 0
It might also be noted that in this context, the Dim statement is superfluous. ReDim is a dynamic Dim statement.

The ReDim statement that you present could also be written:

ReDim DC(LCol-6) As Variant
or
ReDim DC(0 to LCol-6) As Variant

I prefer the latter because it makes the lower bound (zero) explicit.

Otherwise, the code can be broken by the addition of an Option Base 1 statement at the beginning of the module, because the code presumes a lower bound of zero (For i = 0 ...).

Of course, for maximum flexibility, we could write:

For i = LBound(DC) to UBound(DC)

But there might be other parts of the code that presume a lower bound of zero.
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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