0
votes

I'm having issues pulling out data from an excel file I've filter via Range.AutoFilter.

I'm looping through an excel file looking for different data, thus having to "re-apply" the AutoFilter to return different results. The first time I apply the AutoFilter and run the SpecialCells(XlCellType.xlCellTypeVisible), I'm able to pull the data I've needed. However, when the loop returns back to the AutoFilter to filter for new data, the SpecialCells(XlCellType.xlCellTypeVisible) doesn't seem to pull in the new data (just the excel headers).

I've used the Application.Visible = true; to prove that the AutoFilter is filtering with the new data, but it seems the SpecialCells(XlCellType.xlCellTypeVisible) doesn't want to pick up the newly filtered data. See below how I'm applying the AutoFilter within the loop and how I'm pulling the data. Can somebody give me guidance on what I'm doing wrong?

for(int row = 0, row < lineCount; row++)
{
.
.
.
//Other stuff not relate to filters happening
.
.
.
xlAppL.Visible = true;
xlRangeL.AutoFilter(<col>,<row>); //I can see this applying the new filter.
Range filterLines = xlRangeL.Cells.SpecialCells(XlCellType.xlCellTypeVisible);

Range aditionalFilter = filterLines.Areas[areaId];
object[,] af = aditionalFilter.Value2;
int linesCount = af.GetLength(0);
//Do stuff with the new filter

The filterLines doesn't seem to pick up the new filtered data when using the xlRangeL.Cells.SpecialCells(XlCellType.xlCellTypeVisible);...

1

1 Answers

0
votes

Not sure if it was the best solution, but I was able to correct this myself by passing the range to a new method and have the data loop through that new method.