tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,924
- Office Version
- 365
- 2019
- Platform
- Windows
I have some data (spanning a few hundred thousand rows) in column A, such as:
ClsData:
Standard Module:
The code above works but seems to take a long time on this line:
Why is that?
Thanks
PS I know I could use a VLookup instead!
Code:
Day
Monday
Tuesday
Friday
ClsData:
Code:
Option Explicit
Private pDayOfWeek As String
Private pFruit As String
Public Property Get DayOfWeek() As String
DayOfWeek = pDayOfWeek
End Property
Public Property Let DayOfWeek(ByVal D As String)
pDayOfWeek = D
End Property
Public Property Get Fruit() As String
Fruit = pDayOfWeek
End Property
Public Property Let Fruit(ByVal F As String)
pDayOfWeek = F
End Property
Standard Module:
Code:
Option Explicit
Sub Test()
Dim DataArray() As Variant
DataArray = Sheet1.Cells(1, 1).CurrentRegion.Value
Dim DataArrayRows As Long
DataArrayRows = UBound(DataArray(), 1)
Dim FruitArray() As Variant
ReDim FruitArray(1 To DataArrayRows, 1 To 1) As Variant
Dim Counter As Long
Dim MyData As ClsData
Dim MyColl As Collection
Set MyColl = New Collection
For Counter = 2 To DataArrayRows
Set MyData = New ClsData
MyData.DayOfWeek = DataArray(Counter, 1)
Select Case MyData.DayOfWeek
Case "Monday"
MyData.Fruit = "Orange"
Case "Tuesday"
MyData.Fruit = "Apple"
Case Else
MyData.Fruit = "Banana"
End Select
MyColl.Add MyData
Next Counter
For Counter = 1 To DataArrayRows - 1
FruitArray(Counter, 1) = MyColl.Item(Counter).Fruit
Next Counter
Sheet1.Cells(2, 2).Resize(DataArrayRows, 1).Value = FruitArray()
End Sub
The code above works but seems to take a long time on this line:
Code:
For Counter = 1 To DataArrayRows - 1
FruitArray(Counter, 1) = MyColl.Item(Counter).Fruit
Next Counter
Why is that?
Thanks
PS I know I could use a VLookup instead!
Last edited: