From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get data from an Excel Autofilter Range?

Solved!
Go to solution

I have a spreadsheet with a large number of rows (5000) from which I want to extract data.  I have successfully opened The Workbook, Setup an autofilter and filtered the data to select the data matching the criteria using the invoke and property nodes of the Excel ActiveX object.  I now need to get the selected data into an array for further processing and this is where I get stuck.  Excel help online seems to suggest creating a Range Object using special cells with the type xlCellTypeVisible.  If I Range.Count I get the right number of cells but Range.Value2 produces a variant which only contains the first block of data (An autofiltered Range seems to be made up of several non continuous blocks).  Does anybody know how I can read the contents of the entire range into an array of strings?

Thanks in advance

Ken

 

0 Kudos
Message 1 of 7
(3,640 Views)

Hi Ken,

 

You need to use the range and get text properties of the ActiveX class in order to read out the data in a string array format, the attached snipped shows these propertiestext_from_range.png.

 

Hope this helps!

 

-rsw

 

Applications Engineer
0 Kudos
Message 2 of 7
(3,615 Views)

Thanks for your answer but it does not help.

 

I could not work out why Numeric1 and Numeric2 were concatenated with 'A' and wired to Cell1 and Cell2.

 

You may have missed the point of my question.  The snippet below is a very elegant way of getting the text form each cell and putting it in an array of strings which is what (I think) your snippet does.  However this only works if the range is continuous e.g.. A2:G9 (7 rows by 7 columns).  The Autofiltered range (with SpecialCells Type xlCellTypeVisible) is non continuous e.g.. A2:G3, A6:G10, A15:G17 (10 rows by 7 columns).  In this example the snippet only returns A2:G3

 

 

Another way round may be to get the row numbers of the cells in column A of this non continuous range and read them in one row at a time.  Any thoughts on how this may be achieved?

 

Thanks for your interest

 

Ken

0 Kudos
Message 3 of 7
(3,608 Views)
Solution
Accepted by topic author Ken_Naylor

SOLVED IT!!!

 

Found a property call areas which returns a collection of areas each one a continuous range object.  Simply cycled through these areas using the earlier technique building the array as I go.  See below

 

 

Thanks

 

Ken

 

PS  can I KUDOS myself Smiley Happy

0 Kudos
Message 4 of 7
(3,604 Views)

I met the same problem.Can you share how do you solve the problem. Thank you very much!

0 Kudos
Message 5 of 7
(2,359 Views)

It was a while ago when I did this but found it eventually

 

Good Luck

 

Ken

0 Kudos
Message 6 of 7
(2,334 Views)

Thank you very much for helping me.

0 Kudos
Message 7 of 7
(2,305 Views)