+ Reply to Thread
Results 1 to 4 of 4

COUNTIFS in VBA Macro?

  1. #1
    Registered User
    Join Date
    03-07-2017
    Location
    Texas
    MS-Off Ver
    Office 2016
    Posts
    39

    COUNTIFS in VBA Macro?

    Hi, everyone. I'm trying to use the following in a VBA macro, but it just doesn't want to work for me. I'm getting "Expected: End of Statement." I understand it's because of the quotation marks, but it's the only way I thought I could pull in ">0." Basically, I'm trying

    Here was the original line of code:

    TempString = "IF(RC[4]>0,""1,"","""")

    Here is the code I'm trying to use. Basically, I want it to use two conditions, rather than one now:

    TempString = "IF(COUNTIFS(R[-1]C[4],"*MAP*", RC[4], ">0"),""1,"","""")"

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: COUNTIFS in VBA Macro?

    First thing I see is you need to start the formula with an "=" sign is should be "=IF(COUNTIFS(R[-1]C[4],"*MAP*", RC[4], ">0"),""1,"","""")"

  3. #3
    Registered User
    Join Date
    03-07-2017
    Location
    Texas
    MS-Off Ver
    Office 2016
    Posts
    39

    Re: COUNTIFS in VBA Macro?

    Thank you, davesexcel. I have a question about performance. I'm trying to count cell values ONLY when the column name is like Math, Science, or History. The issue is that the code is somewhat static. If a Math, History, or Science column is deleted, it throws off the counts and ends up counting the next column that should be in the spot of one of the grades. I want columns to only be counted when the column name is Math, Sci, or History.

    Before macro
    Attachment 717578

    After macro
    Attachment 717579

    After macro (when a column was deleted beforehand)
    Attachment 717580

    My updates are slowing down performance considerably (from a minute to 5+ minutes). Is there anything I can do? Columns("G:G") is the updated code. Code("H:H") and ("I:I") are the original code that I had.

    Please Login or Register  to view this content.
    Last edited by cluelessdood; 02-07-2021 at 10:25 PM.

  4. #4
    Registered User
    Join Date
    03-07-2017
    Location
    Texas
    MS-Off Ver
    Office 2016
    Posts
    39

    Re: COUNTIFS in VBA Macro?

    I've attached sample file.
    Attached Files Attached Files

+ 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: 6
    Last Post: 03-19-2019, 09:14 PM
  2. [SOLVED] Sumproduct to replace countifs as countifs don't work on external source reference
    By KrishnaSagar in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-02-2017, 02:33 AM
  3. CountIfs Macro
    By Shellybelly in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-02-2015, 01:32 PM
  4. [SOLVED] COUNTIFS in macro
    By adamsc57 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-30-2015, 12:50 AM
  5. How to put COUNTIFS formula in Macro
    By Manish_Gupta in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2014, 07:31 AM
  6. Replies: 0
    Last Post: 12-16-2011, 09:01 AM
  7. Countifs Macro
    By DanMurphy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-02-2010, 10:52 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