PDA

View Full Version : Array Question - basic



malleshg24
02-11-2018, 11:41 AM
Hi Team

I know array start with zero by default, by declaring option base1 it will start from 1 ,

is it possible to start an array from 2?... plz help new in array



Regards,
Mallesh

SamT
02-11-2018, 11:56 AM
Dim myArray(2 to 10)
Dim SomeVariable As Variant
Dim OtherVar(1 to 10, 1 to 10)
ReDim SomeVariable(2 to 20)
Redim OtherVar(2 to 11, 2 to 11)

Paul_Hossler
02-12-2018, 05:11 PM
You can (as Sam said) start arrays at any start/end

The Option Base is for when you do NOT explicitly specify

So if you can pick your bounds correctly, you can make life easier. You should use LBound and UBound

Example: working with rows 16 to 32



Dim A (16 to 32) as Long

For r = LBound(A) to UBound(A)
Cells(r,1).Value = 2*Cells(r,2)
Next r




or even use enumerations



Dim D(vbSunday to vbSaturday)



If you define your own enumerations, it does help readability



Enum colNames
FName =12
LName = 13
Addr = 14
End Enum

Dim N(FName to Addr)