+ Reply to Thread
Results 1 to 3 of 3

VB Countif Help

  1. #1
    Registered User
    Join Date
    06-04-2010
    Location
    Bolton, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    VB Countif Help

    Hi,

    I've been struggling for the past few hours to get a countif function working in VBA. I have workbook that imports data and they creates a new sheet for item I wish. In this case it's cost centre. Within the workbook I have a summary sheet showing totals by cost centre. It's all fine and dandy getting the totals, using a simple sum. However I'm having a problem when I need to introduce an 'if'.

    Please Login or Register  to view this content.
    In terms of the declaration of targetsheet and lastrow2, these are fine as I have no problems when Im doing a simple sum, example below;

    Please Login or Register  to view this content.
    I suspect it's the structure of my formula, but after a few hours im having no luck at all. Anyone any idea's on how to get the top one working?

    Cheers,
    Lee

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Countif Help

    Hello Lee,

    Getting the quotes in the right place can be a headache. Try this version of your formula (all one line)...
    Range("G" & X).FormulaArray = "=COUNT(IF(targetsheet(C2:C" & lastrow2 & ")=""Permanent"",targetsheet(""A2:A""" & lastrow & "2,0))"
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VB Countif Help

    The first bit of OP code is putting an array formula in a cell.
    The second bit of code is putting a value into the cell.

    Do you want the array formula in the cell or do you want the result of the array formula put in the cell as a constant?
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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