View Full Version : Excel VBA code to get Autofiltered data to array
sskannan
12-02-2009, 01:21 AM
Hi All,
I hope someone may be able to help please
I have an Excel sheet with range A1:L42 contain various data
the first row is the hedding row with Auto filter set
I can set the Autofilter programatically, but I am unable to get that filtered data into an array or collection.
Could any body know how to do this, please help me.
Thanks,
Khan
Bob Phillips
12-02-2009, 02:02 AM
Dim LastRow As Long
Dim i As Long
Dim sh As Worksheet
Dim rng As Range
Dim ary As Variant
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Set rng = Range("A1:L1").Resize(LastRow).SpecialCells(xlCellTypeVisible)
End With
Application.ScreenUpdating = False
Set sh = Worksheets.Add
rng.Copy sh.Range("A1")
ary = sh.Range(sh.Range("A1"), sh.Range("A1").End(xlDown)).Resize(, 12)
Application.DisplayAlerts = False
sh.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
sskannan
12-02-2009, 02:27 AM
Hi James,
Thanks very much for your help.
Is that possible to get the data into an array without add a new sheet ?
Please let me know.
Thanks,
Khan
sskannan
12-02-2009, 02:31 AM
Hi James,
Also I don't need the Headdings in the array, need only tha filtered data , Is that possible to get that.
Thanks,
Kan
sskannan
12-02-2009, 02:44 AM
Hi James,
I sort that header problem, the only bit I would like to know is to get the data into array with out add and delete new work sheet.
Is that possible ?
Thanks,
Khan
Bob Phillips
12-02-2009, 02:47 AM
Why is it an issue, we delete it afterwards so it is temporary.
sskannan
12-02-2009, 03:06 AM
Hi James,
The problem is I need to use this array to fill the form combo boxes.
I need to get the Unique values for the filtered rows and fill the combo for user selection.
I am just thinking any easy way out for this
Thanks,
Khan
Bob Phillips
12-02-2009, 03:44 AM
This can be used in that way. What problem are you envisaging?
sskannan
12-02-2009, 05:50 AM
Hi James,
Some time LastRow return 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
I could not find the reason , do you know why ?
Thanks,
Khan
Bob Phillips
12-02-2009, 06:18 AM
Without seeing the data, I can only guess that there is only one row.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.