+ Reply to Thread
Results 1 to 4 of 4

VBA countif based on multiple criteria - paste to a summary table in another sheet

Hybrid View

sloshpuppy VBA countif based on multiple... 04-26-2018, 06:20 AM
AlphaFrog Re: VBA countif based on... 04-26-2018, 06:59 AM
sloshpuppy Re: VBA countif based on... 04-26-2018, 07:08 AM
AlphaFrog Re: VBA countif based on... 04-26-2018, 07:15 AM
  1. #1
    Registered User
    Join Date
    08-30-2017
    Location
    SHEFFIELD,ENGLAND
    MS-Off Ver
    2016
    Posts
    37

    VBA countif based on multiple criteria - paste to a summary table in another sheet

    Hi,

    This is driving me crazy - please help !!!!

    I want to execute a Countif in VBA based on multiple criteria then paste the information into a summary table in another sheet.

    for example: - in my workbook I have two tabs "Sheet 1" is called Import, "Sheet 2" is called Summary.

    Ideally I want to paste a mass data set into the Import tab (columns A:Q) row 1 is the header. The data set can vary in number of rows for example, one day it could be 600 rows another day it could be 300 and so on. Basically its not a fixed range however, the data I am counting will always be in column A - if that makes sense?


    Executing the VBA will count down column A to the last row in the Import Sheet based on the criteria I set and then paste the results into a table in the Summary sheet. The table has headings corresponding to what the Countif is counting which is always static.

    The process is repeated everyday - so the criteria being counted needs to paste in the next available row in the table located in the summary sheet.

    I have created a mock up workbook using countries as the imported data set to kind help with what i am trying to achieve.


    Any help or pointers will be a massive help

    I've tried google and managed to find this but its too static, I am unsure how to manipulate this to achieve my goal?


    Countif2()
    
    Range("F2").Value = Application.WorksheetFunction.CountIf(Range("a2:a800"), "USA")
    
    End Sub

    Best wishes



    Slosh
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: VBA countif based on multiple criteria - paste to a summary table in another sheet

    Sub Countif2()
        
        Dim rng As Range
        Set rng = Sheets("Import").Range("A:A")
        
        With Sheets("Summary").ListObjects(1).ListRows.Add.Range
        
            .Cells(1, "A").Value = Date
        
            .Cells(1, "B").Value = Application.CountIf(rng, "USA") + _
                                   Application.CountIf(rng, "UK") + _
                                   Application.CountIf(rng, "FRANCE")
                                 
            .Cells(1, "C").Value = Application.CountIf(rng, "JAPAN")
            
            .Cells(1, "D").Value = Application.CountIf(rng, "CHINA")
            
            .Cells(1, "E").Value = Application.CountIf(rng, "KOREA")
            
            .Cells(1, "F").Value = Application.CountIf(rng, "HOLAND")
            
            .Cells(1, "G").Value = Application.CountIf(rng, "SPAIN") + _
                                   Application.CountIf(rng, "PORTUGAL")
                                 
            .Cells(1, "H").Value = Application.CountIf(rng, "POLAND")
            
        End With
        
    End Sub
    Last edited by AlphaFrog; 04-26-2018 at 07:08 AM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    08-30-2017
    Location
    SHEFFIELD,ENGLAND
    MS-Off Ver
    2016
    Posts
    37

    Re: VBA countif based on multiple criteria - paste to a summary table in another sheet

    Absolutely bloody brilliant AlphaFrog

    Power of the people

    Much appreciated


    Slosh

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: VBA countif based on multiple criteria - paste to a summary table in another sheet

    You're welcome. Thanks for the feedback.

    I tweaked it a bit to make it a little more concise. Essentially it's the same code. See the post above.

+ 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. Replies: 2
    Last Post: 12-09-2015, 05:43 AM
  2. [SOLVED] Copy and paste specific cell to another sheet based on multiple criteria
    By impresxy in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-09-2015, 07:11 AM
  3. Replies: 1
    Last Post: 06-03-2015, 06:27 PM
  4. Generating a data summary sheet based on multiple criteria
    By Anuru in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 07-18-2014, 08:03 PM
  5. Replies: 2
    Last Post: 04-16-2013, 06:17 AM
  6. Replies: 8
    Last Post: 08-08-2010, 06:10 AM
  7. Copy\Paste multiple criteria based rows to new sheet
    By namz in forum Excel Programming / VBA / Macros
    Replies: 46
    Last Post: 06-06-2008, 08:08 AM

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