title: VBA: Create an array of class module
body: <p>I'm trying to create an array of my custom class, but it gives me this error:</p>
  <blockquote>
  <p>Run-time error '91':</p>
  <p>Object variable or With block variable not set</p>
  </blockquote>
  <p>Here is my code so far:</p>
  <pre><code>Sub DBM_Format()
  
  Dim coreWS As Worksheet
  Dim WS As Worksheet
  Dim LastRow As Long
  Dim RowRange As Long
  Dim dataList() As clsDBM
  Dim tmpdate As Date
     
  Set coreWS = Sheets(ActiveSheet.Name)
  'Set WS = Sheets.Add
  
  
  LastRow = coreWS.Columns(&quot;A&quot;).Cells.Find(&quot;*&quot;, SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).row
  RowRange = LastRow - 1
  
  Dim row As Integer
  ReDim Preserve dataList(RowRange)
  Dim i As Integer
  Dim tmpData As clsDBM
  
  For i = 0 To (RowRange - 1)
      row = i + 2
      tmpData.setDate = Format(Cells(row, 2), &quot;MM/dd/yyyy hh:mm:ss&quot;)
      tmpData.setBloodGlucose = Cells(row, 3)
      tmpData.setCH = Cells(row, 4)
      tmpData.setInzulinF = Cells(row, 5)
      tmpData.setInzulinL = Cells(row, 6)
      tmpData.setCategory = Cells(row, 8)
      tmpData.setDayOfWeek = Weekday(dataList(i).pDate, vbMonday)
      'dataList(i).setDate = Format(Cells(row, 2), &quot;MM/dd/yyyy hh:mm:ss&quot;)
      'dataList(i).setBloodGlucose = Cells(row, 3)
      'dataList(i).setCH = Cells(row, 4)
      'dataList(i).setInzulinF = Cells(row, 5)
      'dataList(i).setInzulinL = Cells(row, 6)
      'dataList(i).setCategory = Cells(row, 8)
      'dataList(i).setDayOfWeek = Weekday(dataList(i).pDate, vbMonday)
      
      Set dataList(i) = tmpData
  Next i
  End Sub
  </code></pre>
  <p>And the class module:</p>
  <pre><code>Option Explicit
  
  Public pDayOfWeek As Integer
  Public pDate As Date
  Public pBloodGlucose As Double
  Public pCH As Double
  Public pInzulinF As Double
  Public pInzulinL As Double
  Public pCategory As String
  Public Property Let setDayOfWeek(Value As Integer)
      pDayOfWeek = Value
  End Property
  Public Property Let setDate(Value As Date)
      pDate = Value
  End Property
  Public Property Let setBloodGlucose(Value As Double)
      pBloodGlucose = Value
  End Property
  Public Property Let setCH(Value As String)
      If IsNumeric(Value) Then
          setCH = CDbl(Value)
      Else
          setCH = 0
      End If
  End Property
  Public Property Let setInzulinF(Value As String)
      If IsNumeric(Value) Then
          pInzulinF = CDbl(Value)
      Else
          pInzulinF = 0
      End If
  End Property
  Public Property Let setInzulinL(Value As String)
      If IsNumeric(Value) Then
          pInzulinL = CDbl(Value)
      Else
          pInzulinL = 0
      End If
  End Property
  Public Property Let setCategory(Value As String)
      If Value = &quot;Something&quot; Then
          If Hour(pDate) &lt; 9 Then
              pCategory = &quot;Something&quot;
          ElseIf Hour(pDate) &lt; 11 Then
              pCategory = &quot;Something&quot;
          ElseIf Hour(pDate) &lt; 14 Then
              pCategory = &quot;Something&quot;
          ElseIf Hour(pDate) &lt; 16 Then
              pCategory = &quot;Something&quot;
          ElseIf Hour(pDate) &lt; 19 Then
              pCategory = &quot;Something&quot;
          ElseIf Hour(pDate) &lt; 21 Then
              pCategory = &quot;Something&quot;
          End If
      Else
          pCategory = Value
      End If
      
      pCategory = Value
  End Property
  </code></pre>
  <p>So my class name is &quot;clsDBM&quot; and I'm trying to fill this array with corresponding data from a whorksheet. The table is well-formatted, there is no empty lines, so that is not the problem, but I can't figure out what is...</p>
  <p>Is there a way to fix it and make this happen (or should I use a completely different approach :D)</p>
  <p>Thanks in advance!</p>