How come only p.Description is multiplied by 10?
Printable View
How come only p.Description is multiplied by 10?
Because it's in the code:
p.Description = "kk" & j * 10
Since the array is already typed as Product, I really didn't need the intermediate variable (T)
There's still no way to assign to the array in one swell foop, but I usually go for readability since there doesn't seem to be a performance issue
Code:Option Explicit
Type Product
Code As String
Description As String
Cost As Currency
Qty As Integer
Retail As Currency
End Type
Sub Test()
Dim Arr(1 To 10) As Product
Dim Rng As Range
Dim i As Long
Set Rng = ActiveSheet.Range("A1:E10")
For i = 1 To 10
With Arr(i)
.Code = Rng.Cells(i, 1).Value
.Description = Rng.Cells(i, 2).Value
.Cost = Rng.Cells(i, 3).Value
.Qty = Rng.Cells(i, 4).Value
.Retail = Rng.Cells(i, 5).Value
End With
Next I
MsgBox Arr(2).Code
MsgBox Arr(4).Description
End Sub