Reputation: 331
I'm not sure what's going on, I though it'd be a simple code.
Basically, I'm just creating an array list based whether or not a cell value is True. But I'm getting the error when setting the array to the cell value. Did I miss something?
Sub test()
Dim chklst() As String
Dim i As Long
With Worksheets("Select")
For i = 1 To 10
If .Cells(14 + i, 12).Value = "True" Then
chklst() = .Cells(14 + i, 13).Value 'This is where the error shows up
End If
Next i
End With
End Sub
When adding a watch, it found that .Cells(14 + i, 13).Value
is a Variant/String. Changing the variable to Variant doesn't work. Changing .Value to .Text doesn't work either.. Help.
Upvotes: 1
Views: 227
Reputation: 152660
You have not declared the size of the array. Without declaring the size there is no where to put anything.
Sub test()
With Worksheets("Select")
Dim chklst() As String
ReDim chklst(1 To Application.CountIf(.Range(.Cells(15, 12), .Cells(24, 12)), "True"))
Dim i As Long
For i = 1 To 10
If .Cells(14 + i, 12).Value = "True" Then
chklst(i) = .Cells(14 + i, 13).Value 'This is where the error shows up
End If
Next i
End With
End Sub
Upvotes: 3