+ Reply to Thread
Results 1 to 5 of 5

Need Help in Countif and Average in VBA Coding.

  1. #1
    Registered User
    Join Date
    04-05-2011
    Location
    A, A
    MS-Off Ver
    Excel 2003
    Posts
    28

    Need Help in Countif and Average in VBA Coding.

    Hi,

    I have an excel workbook in which, sheet1 contains the responses from the clients and sheet2 shows the output which is generated from the sheet1.

    Now I need following output:-

    1. In Sheet2, C2 should be equal to Total number of responses from sheet 1.

    2. In sheet2, Column B should copy the question no. from sheet1 which is starting from Row1.

    3. In sheet2, Column C should show count of response whose value is greater than 3 from sheet1 against their Question No.

    4. In sheet2, also show the average of Cummincation, Total Rewards etc...

    I am also attaching the files for your reference. Please help me asap I need very urgently.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Need Help in Countif and Average in VBA Coding.

    Like this?

    Yogesh%20test(1).xls

  3. #3
    Registered User
    Join Date
    04-05-2011
    Location
    A, A
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Need Help in Countif and Average in VBA Coding.

    Thanks Dude. Bu it is very complicated formula....Can you please put some easy forumla which I can undestand.

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Need Help in Countif and Average in VBA Coding.

    Yes, the formula can be made easier, but it will make them harder to work with.

    The simplest formula for cell B4 in Sheet 2 is:

    =Sheet1!D1

    And for C4:

    =COUNTIF(Sheet1!D2:D50000,">3")/$C$2

    The issue is that when we copy these formula down to cells B5 and C5 Excel changes them to:

    =Sheet1!D2
    =COUNTIF(Sheet1!D3:D50001,">3")/$C$2

    Respectively, whereas we actually want them to be:

    =Sheet1!E1
    =COUNTIF(Sheet1!E2:E50000,">3")/$C$2

    So, to get this we have to either:

    a. Manually edit each formula after we've copied it to correct it, or
    b. Use another formula to explain to Excel that we want a change of row in sheet 2 to represent a change of column in Sheet 1. I've used the OFFSET function to do this, but INDIRECT and TRANSPOSE are also candidates. Although, for my money, OFFSET is the most straightforward for this application.

    Similiarly with the group averages, the simplest formula for C3 is;

    =AVERAGE(C4:C9)

    But if we copy this to C10 it gives the wrong result, because "Total rewards" has only 5 questions, compared to "Communications" 6, so we'd need to change the formula from:

    =AVERAGE(C11:C16)

    To:

    =AVERAGE(C11:C15)

    So, basically, if you make the formula simpler you're having to manually edit just about every single one to get the right results.

    If you want to do that then that's up to you, but I'd suggest taking an hour or so to work out how my formula work, because they make life much easier.
    Last edited by Andrew-R; 01-04-2012 at 05:18 AM.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Need Help in Countif and Average in VBA Coding.

    In cell C3:

    PHP Code: 
    =AVERAGE(OFFSET(C4,,,MATCH(TRUE,INDEX(B4:B5000="",0),0)-1)) 



+ 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