AAP
Member
Base 0 = LBound(Array) = Count begins from 0
Base 1 = LBound(Array) = Count begins from 1
So when you define array size as 1 in default case it means two rows or two columns depending on the dimension. So after making it option base 1 the dimension matches correctly.
It is not really the dimension but the sizing the array when you are ReDim-ing. You are arriving LRow which is last row (138) and therefore Array will have 138 elements. At the end of code it will have 137 rows populated and one empty row. So your dimension reference has to be correct.
So following code will work.
Code:Option Explicit Option Base 1 Sub LearnArray() Dim BrandModel() As Variant Dim Brand() As Variant Dim Model() As Variant Dim x, Lrow As Long If WorksheetFunction.CountA(Cells) > 0 Then Lrow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row End If BrandModel = Sheet1.Range(Cells(2, 1), Cells(Lrow, 1)).Value ReDim Brand(1 To UBound(BrandModel), 1) '// Notice it takes limit from ReDim Model(1 To UBound(BrandModel), 1) '// BrandModel array size For x = LBound(BrandModel) To UBound(BrandModel) Brand(x, 1) = Left(BrandModel(x, 1), InStr(BrandModel(x, 1), " ")) Model(x, 1) = Replace(BrandModel(x, 1), Brand(x, 1), "") Next x Sheet1.Range(Cells(2, 3), Cells(Lrow, 3)).Value = Brand Sheet1.Range(Cells(2, 4), Cells(Lrow, 4)).Value = Model End Sub
Dear Shrivallabha,
If you please take a look at my new thread and help me there because you are more into my understanding of Arrays. Please..Thanks a lot Again.