+ Reply to Thread
Results 1 to 15 of 15

COUNTIFS Does not Return Results for UK based users

  1. #1
    Registered User
    Join Date
    09-27-2017
    Location
    Kitchener, Ontario
    MS-Off Ver
    2016
    Posts
    5

    COUNTIFS Does not Return Results for UK based users

    Hello - I'm sure this has been covered somewhere but I've been searching for days with no success. Sharing the spreadsheet will require a lot of work to allow me to release it so hopefully I've been clear enough with my notes below.

    First the problem - I have a Macro that performs a COUNTIFS for a number of things including a Greater Than Or Equal To date and a Less Than OR Equal To date. I am based in North America and this works perfectly for any other users in North America. UK based users return no matches unless I comment out the Date filters in the COUNTIFS.

    Background:
    - My Excel file needs to import source data (from .xlsx) that does not have a consistent file naming convention so I have a "file picker" that allows the user to select the proper source file and then the VBA script will copy the data and paste it to a Worksheet (InputSheet). Clearing out data with minimal user interaction between each use of the spreadsheet is critical so I have not looked at a "Data -> Get Data" import.
    - The dates in the source file are in format yyyy-mm-dd hh:mm so I have a formula column in the InputSheet where I use "=INT(B2)" to get it into a date format
    - Created a second formula column, for UK date format, in InputSheet where I use "=INT(B2) to get it into a date format
    - Users in US set the date range for the report by typing in a start date and end date (in UserInputSheet) in format mm/dd/yyyy
    - Users in UK set the date range for the report by typing in a start date and end date (in UserInputSheet) in format dd/mm/yyyy
    - Table Data and a Chart are presented in OutputSheet


    Sample of the CountIfs for US (part of a For Loop):
    OutputSheet.Cells(6, column).Value = Application.WorksheetFunction.CountIfs( _
    InputSheet.Range(InputSheet.Cells(2, 3), InputSheet.Cells(Rows, 3)), Worksheets("OutputSheet").Cells(3, Column), _
    InputSheet.Range(InputSheet.Cells(2, 5), InputSheet.Cells(Rows, 5)), Worksheets("OutputSheet").Cells(6, 1), _
    InputSheet.Range(InputSheet.Cells(2, 10), InputSheet.Cells(Rows, 10)), ">=" & UserInputSheet.Range("B1"), _
    InputSheet.Range(InputSheet.Cells(2, 10), InputSheet.Cells(Rows, 10)), "<=" & UserInputSheet.Range("B2"))

    Sample of the CountIfs for US (part of a For Loop):
    OutputSheet.Cells(6, column).Value = Application.WorksheetFunction.CountIfs( _
    InputSheet.Range(InputSheet.Cells(2, 3), InputSheet.Cells(Rows, 3)), Worksheets("OutputSheet").Cells(3, Column), _
    InputSheet.Range(InputSheet.Cells(2, 5), InputSheet.Cells(Rows, 5)), Worksheets("OutputSheet").Cells(6, 1), _
    InputSheet.Range(InputSheet.Cells(2, 11), InputSheet.Cells(Rows, 11)), ">=" & UserInputSheet.Range("E1"), _
    InputSheet.Range(InputSheet.Cells(2, 11), InputSheet.Cells(Rows, 11)), "<=" & UserInputSheet.Range("E2"))

    Each of the above are their own Sub to avoid any issues. They are identical other than the column I'm looking at for the date of the source data and the cells I'm looking at for the date range.

    Dates in UserInputSheet are Date format 2012-03-14 "English United States"
    Dates in US Calculated column in InputSheetare Date format mm/dd/yyyy "English United States"
    Dates in UK Calculated column in InputSheetare Date format dd/mm/yyyy "English United Kingdom"

    If I set my PC to English United Kingdom in the Control Panel Region it makes no differerence. The US script still works and the UK script still fails.

    My guess right now is that the INT formula isn't ideal.

    Any help would be greatly appreciated!
    Attached Files Attached Files
    Last edited by SDillon; 03-14-2020 at 11:09 PM.

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: COUNTIFS Does not Return Results for UK based users

    A date in Excel is evaluate as the number of days between the date you entered and 1 january 1900.
    Using =INT(B2) means you do not want to care about hours, minutes..
    The display of the date can be in UK, US or other format, it does not change the value.
    So you should not need 2 codes, one for US one for UK.
    Can you attach a short Excel sample of you data with dates to make your code running .
    Last edited by PCI; 03-15-2020 at 04:39 AM. Reason: Typo
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    09-27-2017
    Location
    Kitchener, Ontario
    MS-Off Ver
    2016
    Posts
    5

    Re: COUNTIFS Does not Return Results for UK based users

    Thanks for your answer. I've attached a sample file to my original post that removed anything not relevant to this particular issue. I use the Input Page as there are a number of worksheets that display different visualizations of the data from a common date range.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: COUNTIFS Does not Return Results for UK based users

    caldate =InputSheet!$J$2:$J$26
    enddate =UserInput!$B$2
    Location =InputSheet!$C$2:$C$26
    startdate =UserInput!$B$1
    sub_cat =InputSheet!$F$2:$F$26
    =SUMPRODUCT(--(caldate>=startdate),--(caldate<=enddate),--(Location=B$20),--(sub_cat=$A21))
    Ben Van Johnson

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    Whatever the date format, the country, …
    here the easy way is to directly work with an original formula,
    as a VBA beginner starter let's see first the COUNTIFS formula :
    Please Login or Register  to view this content.
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb

    Once the previous EZ principle understood,
    according to the attachment and its code see this dynamic revamped VBA COUNTIFS formula (edit v3) :

    PHP Code: 
    Sub OutputSheetCount()
         
    Dim F$
        
    With Sheet2.UsedRange.Columns
             F 
    "," & .Item(10).Address(External:=True) & ","""
             
    "=COUNTIFS(" & .Item(3).Address(External:=True) & ",B$3," & .Item(6).Address(External:=True) & _
                 
    ",$A4">=" Sheet1.[B1].Value2 """" "<=" Sheet1.[B2].Value2 """)"
        
    End With
        With Sheet3
    .UsedRange.Rows
            With 
    .Range("B2").Resize(.Count 2, .Columns.Count 1)
                 .
    Formula F
                 
    .Formula = .Value2
                  F 
    "=SUM(" & .Columns(1).Address(FalseFalse) & ")"
            
    End With
            With 
    .Cells(.Count2).Resize(, .Columns.Count 1)
                 .
    Formula F
                 
    .Formula = .Value2
            End With
        End With
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 03-15-2020 at 12:54 AM. Reason: adding the sum row, optimization …

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: COUNTIFS Does not Return Results for UK based users

    Do you know that you could ask to the macro do the job of column "Date" and remove this column...!
    Now if you still accept the use of an extra calculated column you could prepared a another one (or change column "Date" to) with next formula:
    =((INT(B2)>=UserInput!$B$1))*((INT(B2)<=UserInput!$B$2))
    and use it in a Pivot Table without macro: See file attached

    Finally, you could include or create a macro to refresh column "Date" and/or "Flag": Copy down formulas as needed
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: COUNTIFS Does not Return Results for UK based users


    SDillon,

    your original code can well work whatever the date format / country
    if you just add the Value2 property to cells in particular for the worksheet 'UserInput' …

  9. #9
    Registered User
    Join Date
    09-27-2017
    Location
    Kitchener, Ontario
    MS-Off Ver
    2016
    Posts
    5

    Re: COUNTIFS Does not Return Results for UK based users

    Thank you all for the input. I will take a look at all of the suggestions and work with them. This will not be tested until tomorrow when my UK based user comes online and can verify.
    Last edited by SDillon; 03-15-2020 at 12:18 PM.

  10. #10
    Registered User
    Join Date
    09-27-2017
    Location
    Kitchener, Ontario
    MS-Off Ver
    2016
    Posts
    5

    Re: COUNTIFS Does not Return Results for UK based users

    The addition of Value2 has been successful with my testing but my user is still reporting 0 search results when including the date filter. Not sure what is happening there as my testing shows that when I set my Windows Region to UK the script fails to return values with .Value but does return with .Value2.

    When I have a chance I'll look at it more fully.

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: COUNTIFS Does not Return Results for UK based users


    According to posts #5, 6 & 8 no issue on my side with your attachment with different Excel & Windows versions
    with the same Windows Regional Settings than your UK users …

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb

    According to your attachment your code revamped :

    PHP Code: 
    Sub OutputSheetCount()
         
    Dim D(), K%, L%, C%, R%
             
    = Array(">=" Sheet1.[B1].Value2"<=" Sheet1.[B2].Value2)
        
    With Sheet3.[A3].CurrentRegion
             K 
    = .Columns.Count
             L 
    = .Rows(.Rows.Count).Row 1
        End With
        With Sheet2
    .UsedRange.Columns
            
    For 2 To K
            
    For 4 To L
                Sheet3
    .Cells(RC) = Application.CountIfs(.Item(3), Sheet3.Cells(3C), _
                        
    .Item(6), Sheet3.Cells(R1), .Item(10), D(0), .Item(10), D(1))
            
    Next R
                Sheet3
    .Cells(RC) = Application.Sum(Range(Sheet3.Cells(4C), Sheet3.Cells(LC)))
            
    Next C
        End With
    End Sub 
    Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !

  13. #13
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: COUNTIFS Does not Return Results for UK based users

    Did you try my formula vs vb code?
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    09-27-2017
    Location
    Kitchener, Ontario
    MS-Off Ver
    2016
    Posts
    5

    Re: COUNTIFS Does not Return Results for UK based users

    Thank you all for your help and time with this. After a live session with the user this morning we were able to successfully have the code execute with the modification from the .Value to .Value2 on any date cells. I'm not sure what happened with the initial test as I've not updated anything since then but the important thing is that it's working.

    Thanks again!!!

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: COUNTIFS Does not Return Results for UK based users


    Yes Value2 is the right property as it does not care about the cell display but only on the real stored value
    as a real date within Excel is nothing else than a number …

    Thanks for the rep' added !

+ 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. Lookup 2 values and return results based on these
    By Philly500 in forum Excel General
    Replies: 4
    Last Post: 08-26-2015, 07:02 AM
  2. Display results based on certain categories of users
    By tnovak in forum Excel General
    Replies: 2
    Last Post: 10-14-2014, 12:51 PM
  3. [SOLVED] Countifs based on two condition and display results only one time
    By kkharis in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-16-2013, 05:56 AM
  4. Countifs should return blank results for blank row of cells
    By Groovicles in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-29-2013, 06:20 PM
  5. Return Results Based on Date Range
    By ExcelSuduko in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-05-2013, 11:23 AM
  6. Replies: 0
    Last Post: 12-16-2011, 09:01 AM
  7. Return results based on multiple criteria
    By Bryce in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-28-2005, 08:05 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