Filtering works manually but creates errors with VBA

keithmcvean

New Member
Joined
Dec 20, 2013
Messages
13
I have a bit of a weird one so bear with me.

I have an macro-enabled Excel spreadsheet (.XLSM) created in Excel 2010. On the first sheet (HoldsList) I have data formatted as a table called Holds (see below) with the autofilter turned on. What I'm trying to do is, using VBA, filter the table where Column Q = True.

It should be simple but it's not.

In column X I have a formula calling a function I wrote myself which works just fine that many other formulas in other columns depend upon. The problem is when I filter the data.

If I filter the data by hand (i.e. clicking the down arrow in the column header and removing the values of FALSE from Column Q) everything works fine. The column is filtered and all data and data derived from functions is correct.

If I filter it using VBA however, Column X updates to #VALUE (a value used in the formula is of the wrong data type).

What is even stranger is that if I make no changes to the data but just click in one of the cells in column x or y and press enter, everything resolves again as it should.

QXY
TRUE=VBAFUNCTION(Column Y)Column Y Data
FALSE=VBAFUNCTION(Column Y)Column Y Data

<tbody>
</tbody>


I'm pretty sure the problem isn't the filtering code (see below).

Filtering Subroutine:

Dim FilterColumn As Integer
FilterColumn = [MATCH("Available", Holds[#Headers], FALSE)]


If Sheets("HoldsList").AutoFilter.FilterMode = False Then
Range("Holds").AutoFilter Field:=FilterColumn, Criteria1:=True

Else
ActiveSheet.ShowAllData

End If

Which leaves the VBAFunction itself. The function itself is long and complicated, but in a nutshell, it takes the data from Column Y, manipulates the text, and returns the result. That function is defined as a string, as is every variable in it, as is all the functions it in turn calls.

I've tried turning on and off the calculations, screen updates, etc. but to no avail.

Any ideas?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,214,560
Messages
6,120,217
Members
448,951
Latest member
jennlynn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top