+ Reply to Thread
Results 1 to 8 of 8

Excel 2016 VBA to generate table using SUMIFS (or appropriate) with multiple criteria

  1. #1
    Registered User
    Join Date
    05-10-2016
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    6

    Excel 2016 VBA to generate table using SUMIFS (or appropriate) with multiple criteria

    Hi guys,

    I really need some help because what I wish to achieve is out of my skill set. I have a table of data to be updated with information as orders are sent; this table has columns for a start date, an end date, a location (country), and a number (of items sent to the location). I have made the location column a named range titled "ORDERS".

    I have a second table of data with a column for a list of countries and a column results to indicate a '1' if the criteria matches and a '0' if the criteria does not match. I have made the countries column a named range titled "COUNTRIES". The sheet which holds the tables is called "Control".

    I need to achieve two outcomes from the data.

    First, I want to be able to enter a date into a cell, lets say $T$5 and when the macro runs to first check that the date is >= start date and <= end date (ie in range); then to check the name of the location and if the number is > 0 to populate the results column with a '1'.

    Second, I want to SUM the data using the same criteria as above (effective date from cell $T$5 to be in range, and for each iteration of the location to sum the number). Locations will appear in multiple rows, hence the requirement to SUM when the criteria fits. I wish for the active data, ie countries that have appeared in date and with a SUM > 0 to appear in a separate and generated table on another sheet within the workbook titled "MainMap", just two columns Country and No. of Orders. If possible the macro would ideally delete a previously generated table (within sheet "MainMap") so that fresh data appears each time.

    Can anyone help me to achieve my aims? Incidentally this will feed into the macro I have created which uses the 1s and 0s from results to change the colour of countries on an EMF of a world map, which is located on "MainMap".

    Many thanks in advance

    Tony

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Excel 2016 VBA to generate table using SUMIFS (or appropriate) with multiple criteria

    It would help a lot if you attached a sample workbook. It will be easier to see the requirement and test the results.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    05-10-2016
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    6

    Re: Excel 2016 VBA to generate table using SUMIFS (or appropriate) with multiple criteria

    Thanks for the response. I have attached the sample to be looked at.

    I have entered a RANDBETWEEN formula in the Results column, if you use the command button on the "MainMap" sheet you will see how the macro currently functions.

    All help is greatly appreciated.
    Attached Files Attached Files

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Excel 2016 VBA to generate table using SUMIFS (or appropriate) with multiple criteria

    I think I got it. You have a table on the Main Map page in columns T:U. You want to enter a date in cell T5. On the Control Sheet, this date will be used to determine if the dates are in range. For countries in range, you want to populate the table on the Main Map page and sum up the orders for those records in range.

    This table will be dynamic.

  5. #5
    Registered User
    Join Date
    05-10-2016
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    6

    Re: Excel 2016 VBA to generate table using SUMIFS (or appropriate) with multiple criteria

    Partly correct yes.

    As well as the table on the MainMap page being dynamic and updating when the macro is run, I also wish for the table on the Control page to update (columns A and B) - column B (Results) to have a 1 when the country appears in the table on the MainMap page. It is this table that drives the colours on the MainMap to be updated.

    :D cheers for looking into this for me.

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Excel 2016 VBA to generate table using SUMIFS (or appropriate) with multiple criteria

    When I really dug into this, it turned out to be easier than I thought. I did make some changes. First of all I converted your static ranges to dynamic ranges using the offset command. I also converted the data on the control page into Excel tables. Excel tables know how big they are and repeat formulas down automatically. You can also use the column headers in formulas an VB code making it easier to code, understand and debug.

    Assigning the results column was fairly easy. I used the formula: =IF(SUMIFS(Table_Dates[number], Table_Dates[location],[@Country],Table_Dates[Date in range],"Yes")>0,1,0) This yields 1 if the country is within date and has more than zero orders.

    As for the table on the MainMap page, a simple pivot table against the data on the Control page does the trick.

    The only piece of VB I added was a small subroutine I have that clears and refreshes pivot tables. I stuck it at the very end of your code. Otherwise you might have to refresh the pivot table manually.

    I also fudged some of the data so I could test it out.

    This looks like a cool application.
    Attached Files Attached Files

  7. #7
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Excel 2016 VBA to generate table using SUMIFS (or appropriate) with multiple criteria


  8. #8
    Registered User
    Join Date
    05-10-2016
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    6

    Re: Excel 2016 VBA to generate table using SUMIFS (or appropriate) with multiple criteria

    You good sir are an uber-legend.

    Many thanks :D

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Fill arrays from sheet / SUMIFS / create & fill table based on multiple criteria
    By Dimitris254 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2016, 09:43 AM
  2. Excel 2016: Pivot table dates - useless!
    By domgilberto in forum Excel General
    Replies: 1
    Last Post: 02-17-2016, 01:43 PM
  3. [SOLVED] Sumifs against financial year 2015-2016
    By silambarasan.J in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-28-2016, 11:41 AM
  4. [SOLVED] Dynamic sumifs in a table with multiple criteria
    By JEAN1972 in forum Excel General
    Replies: 5
    Last Post: 12-04-2015, 07:25 PM
  5. [SOLVED] SUMIFS Equivalent for Excel 2003 with multiple criteria and range arguments
    By DEER30 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-27-2014, 01:19 AM
  6. [SOLVED] Generate List of Records that Match Multiple Criteria from Data Table
    By trandle in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-10-2014, 04:43 PM
  7. Replies: 5
    Last Post: 06-06-2013, 05:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1