Excel

TheSmallman.com

an XL ideas Lab

Dashboards VBA
  • Home
  • Dashboards
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
    • Power Pivot a User Guide
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About
Menu

Excel Dashboards VBA

Street Address
City, State, Zip
Phone Number
an XL ideas Lab

Your Custom Text Here

Excel Dashboards VBA

  • Home
  • Dashboards
  • Excel Tips
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
  • PowerPivot
    • Power Pivot a User Guide
  • Courses
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About

Evaluate and Filter Part 2

April 26, 2015 Marcus Small

This post is a follow up from the blog post earlier in the month on Filtering without a filter.  It is an alternative to the autofilter method I have outlined extensively.  The post focuses on filtering out more than one criteria and putting the results in a fresh sheet.  To do so we use the evaluate method.  This is relatively complex, however if we break down what needs to change we can significantly simplify the process.

What we will do is to test if there is No or Maybe in column 3 of our dataset.  If so we want to move all of those cells to the next sheet called Res.

For starters our data set is simple and looks as follows:

The headers start in row 10 and the dataset is 4 columns in width. Firstly we test if there is data in column 3 which says the word yes. If not there is no need to run the procedure.

If Application.CountIf(Sheet1.Columns(3), "Yes") = 0 Then Exit Sub

Then we tell VBA where the dataset starts from (row 10).

With Sheet1.[a10].CurrentRegion

Now we set the variant (ar).

   ar = Filter(.Parent.Evaluate("transpose(if((" & .Columns(Col).Address & _
   "=""No"")+(" & .Columns(Col).Address & "=""Maybe""),row(1:" & _
   .Rows.Count & "),char(Col)))"), Chr(2), 0)

The above is the complex part but knowing what to change is all important. The column we wish to evaluate is column 3. That column (which says Interest) has the Yes, No or Maybe in it. The following variable:

Dim Col As Integer
Col = 3

It has been included to help with this procedure. Put the column number you are evaluating in after col = ?

Where the question mark represents your column to evaluate.

The next part to change is how large you want the array and which columns you want to include in your output. In the folowing example 4 columns.

   ar = Application.Index(.Value, Application.Transpose(ar), [{1,2,3,4}])

The above includes 4 columns in the array Ar. If you wanted for example columns 1 and 4 the code would look as follows:

   ar = Application.Index(.Value, Application.Transpose(ar), [{1,4}])

If you did change that part you would need to change the size of the output array which is next.

Sheet2.[A2].Resize(UBound(ar, 1), 2).Value = ar

Where 2 is equal to columns (1 and 4). In the full version of this example we will include all 4 columns. The procedure is as follows:

Option Explicit

Sub FilterToNewLoc2Crit()
Dim ar As Variant
Dim Col As Integer

Col = 3

   If Application.CountIf(Sheet1.Columns(3), "Yes") = 0 Then Exit Sub
      With Sheet1.[a10].CurrentRegion
         ar = Filter(.Parent.Evaluate("transpose(if((" & .Columns(Col).Address & _
         "=""No"")+(" & .Columns(Col).Address & "=""Maybe""),row(1:" & _
         .Rows.Count & "),char(2)))"), Chr(2), 0)
         ar = Application.Index(.Value, Application.Transpose(ar), [{1,2,3,4}])
      End With
   Sheet2.[A2].Resize(UBound(ar, 1), 4).Value = ar
End Sub

You will notice the output of this Excel VBA macro goes to sheet2 (the sheet code name).  I will attach a file to show a working version of this method.  I still prefer the autofilter with VBA but this method I assume has real speed.  You can read up on the autofilter method Autofilter.

The Excel file is below.

EvaluateTwo.xls

Tags Excel, VBA, Evaluate, FIlter, autofilter, alternative
← Incident Tracking DashboardExcel Dashboard by Department and Region →

Featured Posts

Excel Dashboards: Tracking a Crisis

Excel Dashboards: Tracking a Crisis
April 14, 2020

Recent Posts

Populating an Excel Table from a Range of Cells with VBA

Populating an Excel Table from a Range of Cells with VBA June 12, 2025

Fuzzy Distribution with Randbetween

Fuzzy Distribution with Randbetween May 21, 2025

Add Minimum and Maximum for Chart in Cells

Add Minimum and Maximum for Chart in Cells March 12, 2025

Inflation Over Multiple Years in a Single Cell

Inflation Over Multiple Years in a Single Cell January 10, 2025

Hubspot Dashboard

Hubspot Dashboard October 3, 2024

Monthly Dashboard With Supporting Metrics

Monthly Dashboard With Supporting Metrics September 25, 2024

Excel Show Missing Sheet Tabs

Excel Show Missing Sheet Tabs July 29, 2024

Run Macro Overnight Automatically

Run Macro Overnight Automatically June 24, 2024

Split File into Parts and Save to Directory

Split File into Parts and Save to Directory April 20, 2024

Most Popular Author

Most Popular Author December 14, 2023

 

Follow US:

 
 

MarcusSmall@thesmallman.com

 

TheSmallman.com - Making your small systems hum...
© Copyright 2013-2024 theSmallman.com All Rights Reserved.