aurelius89
Board Regular
- Joined
- Mar 15, 2017
- Messages
- 69
I have a snippet of code below which will assign a range to an array, all works well:
However, when they result of the .End(xlUP).row is 4 which makes the outcome of the range "AB4:AB4" it throws up an error.
So I changed to this:
Now it lets me assign the range but I cannot put that single cell range into the array. It states "Type mismatch"
What am I doing wrong?
Code:
Dim rngAB As Range
Dim arr() As Variant
Set rngAB = wsWeights.Range("AB4:AB" & wsWeights.Cells(Rows.count, "AB").End(xlUp).Row)
arr = rngAB
However, when they result of the .End(xlUP).row is 4 which makes the outcome of the range "AB4:AB4" it throws up an error.
So I changed to this:
Code:
If wsWeights.Cells(Rows.count, "AB").End(xlUp).Row = 4 Then
Set rngAB = wsWeights.Range("AB4")
arr = rngAB
Else
Set rngAB = wsWeights.Range("AB4:AB" & wsWeights.Cells(Rows.count, "AB").End(xlUp).Row)
arr = rngAB
End If
Now it lets me assign the range but I cannot put that single cell range into the array. It states "Type mismatch"
What am I doing wrong?
Last edited: