+ Reply to Thread
Results 1 to 5 of 5

VBA Application CountIfs code

  1. #1
    Registered User
    Join Date
    12-01-2017
    Location
    New Jersey
    MS-Off Ver
    2016
    Posts
    63

    VBA Application CountIfs code

    I am currently trying to count #N/A in a column based off of 2 criteria in a different column. The excel formula I wrote counts them correctly
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    I adjusted code to also count and notify the user if #N/A errors existed before continuing to process the file. The code runs Ok but always creates the message box even when the actual count is zero. The count of #N/A is always in Column "AS" and the criteria is always in Column "V" using the text terms CSA Or GPA as the criteria If either one exists in Column V with a matching #N/A in column AS, then count 1 for each instance. I must have the code or format wrong. Can you help or offer a better way. Thanks

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: VBA Application CountIfs code

    Instead of the logical bYes you should make it an integer or a long integer
    This will reflect the number of time the N/A exists then if the result is > 0 then show the messagebox
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

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

    Re: VBA Application CountIfs code

    When numeric types are converted to Boolean values, 0 becomes False and all other values become True
    Since bYes is the sum of several counts, > 0 --> True
    However, you never check the status of bYes once the sum is computed you just immediately execut the msg box line no matter what. Use:

    If bYes, then MsgBox
    Last edited by protonLeah; 04-23-2019 at 04:58 PM.
    Ben Van Johnson

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: VBA Application CountIfs code

    True, also good

  5. #5
    Registered User
    Join Date
    12-01-2017
    Location
    New Jersey
    MS-Off Ver
    2016
    Posts
    63

    Re: VBA Application CountIfs code

    Thank You for the help It worked out well

+ 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. Application.WorksheetFunction.CountIfs dates
    By Wijnand1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-11-2018, 06:36 AM
  2. Replies: 0
    Last Post: 07-05-2017, 09:36 PM
  3. [SOLVED] Application.WorksheetFunction.CountIfs Issue - Equal or Greater Than
    By PFDave in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2017, 05:06 AM
  4. [SOLVED] VBA code to change the application.username and application.userinitials
    By jwlamb in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2014, 11:25 PM
  5. more efficient way to do for-loop using application.worksheetfunction.countifs
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 09-08-2013, 10:36 PM
  6. [SOLVED] worksheetfunction countifs, counting down and across, application defined error
    By Lifeseeker in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-16-2012, 11:58 AM
  7. error trying to use "Application.WorksheetFunction.Sum(CountIfs"....in vba
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-20-2011, 09:15 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