nevergiveup
New Member
- Joined
- Jun 2, 2011
- Messages
- 43
I have the code below to transfer the visible cells from a range in excel into an array. In this case, the non-filtered range is a11:a19. Applying the auto-filter, the visible rows become rows 11,12 and 14. However, running the macro below the textbox results include only the text in cells a11 and a12. Since cell a14 is visible (and thus part of the range), why is it not included in the array? What should be changed so that cell a14 also is in myarray?
Supplemental question: if I declared Option Explicit, what DIM statement should be used with x. See For X = ..... in the code below.
Supplemental question: if I declared Option Explicit, what DIM statement should be used with x. See For X = ..... in the code below.
Code:
Sub ArrayFromRange()
Dim firstviscell As Range
Dim visrange As Range
Dim MyArray As Variant
Set firstviscell = Range("firstinlist") ' firstinlist is named cell which happens to be cell "a11"
MyArray = Range(firstviscell, firstviscell.End(xlDown)).SpecialCells(xlCellTypeVisible).Value
For x = LBound(MyArray) To UBound(MyArray)
MsgBox MyArray(x, 1)
Next
End Sub