+ Reply to Thread
Results 1 to 4 of 4

Count functions with variables

  1. #1
    Registered User
    Join Date
    03-09-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    35

    Unhappy Count functions with variables

    Hi Guys,

    I have another request for help. I've been plugging away at my tool. (over 12,000 lines of code now). And I'm struggling with this next bit. The tool will generate a final report (I've attached a sample skeleton) and automatically creates the tabs, names them and formats them. It'll export the data into the "xxx Data" tabs. And I have been able to get it to automatically create the correct number of employees per site automatically.

    Here's the hard part. You'll have to reference the "Prescott" or "PCT" tabs in the file to understand what I'm trying to do. (I had to strip it down so that it would upload, the file was over 3MB.)

    Anyway, COLUMN A of the "PCT Detail" tab has a series of codes. If you look at COLUMN J of "DCT DATA" you will note that those codes correspond. I need a macro to automatically count the number of times each code is used and paste it in the appropriate column (So, For "Employee 1" it'll count them on the PCT Data sheet and then paste the number of times that code was used into Column B of the PCT Detail sheet. Employee 2 would have their results posted into Column D, etc.) Here's the catch, I need this macro do this dynamically. Not all sites have the same number of employees. I dont always know who's going to be listed in Row 2 at any given site, so I need the macro to figure it out all by itself. Frankly, I'm stymied. Any help would be appreciated.

    Thanks!
    Attached Files Attached Files
    Last edited by JohnathanC; 03-18-2010 at 12:11 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Complex Count functions with variables

    Hi

    You can get the result you want by using the formula
    =SUMPRODUCT(--('PCT Data'!$J$2:$J$431='PCT Detail'!$A9),--('PCT Data'!$C$2:$C$431='PCT Detail'!B$2))
    in PCT Detail!B9, and copying down/across as required.

    The ranges will be variable, so if you create a variable that will give you the last row used in PCT Data, then you can build the formula. Once you have it created, the macro can be used to copy down / across based on the number of columns used.

    HTH

    rylo

  3. #3
    Registered User
    Join Date
    03-09-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    35

    Question Re: Complex Count functions with variables

    Quote Originally Posted by rylo View Post
    Hi

    You can get the result you want by using the formula
    =SUMPRODUCT(--('PCT Data'!$J$2:$J$431='PCT Detail'!$A9),--('PCT Data'!$C$2:$C$431='PCT Detail'!B$2))
    in PCT Detail!B9, and copying down/across as required.

    Hi Rylo,
    thanks for your reply! The formula you used above works exactly like I need it to, but I cant seem to figure out how to get it to work as a macro. I know that I can't just use
    Please Login or Register  to view this content.
    But I'm not sure how to work it. Do you have any ideas? Thanks again!

  4. #4
    Registered User
    Join Date
    03-09-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Count functions with variables

    Nevermind. I figured it out;

    Please Login or Register  to view this content.
    Thanks!

+ 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