+ Reply to Thread
Results 1 to 4 of 4

Countif and VBA ?

  1. #1
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    2

    Lightbulb Countif and VBA ?

    The problem I have is, I use =COUNTIF formating to get an overal grade value based on a letter, so A is worth 3 B is worth 2 and so on, all the values are added up then divided by the number of subjects to get an average. We have moved Management Information Systems and the new one does not do the calculations, so I do it in excel, the trouble is that I only want to add up the values where the header row says "Effort" and not "Attainment". I think I need some VBA to work with the COUNTIF but don't know how to get there. I could remove the "Attainment" column altogether but realy need both values side by side to see progress of students. Currently I have one sheet for Attainment and one for Effort. Can any one help.

    Thanks
    Attached Images Attached Images
    Last edited by carlpots; 05-14-2014 at 12:20 PM.

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Countif and VBA ?

    I should re-arange the data, so it is possible to use a povit table.

    Before using the pivot table, I should first add an VLookup formula to get the numbers (instead of a letter).

    If you add an excel file, without confidential information, we can show it to you.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Countif and VBA ?

    My math is probably off, but maybe this can help you get started.

    Please Login or Register  to view this content.
    Ditto post 2. A sample would help alot.

  4. #4
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Countif and VBA ?

    Thanks for the Help, so had a good play with it and this is my working solution to the problem, the change font type, size and colour part is not particularly elegant but works, I think would be better using a similar for next loop as first part but test for the value of A but have not quiet got my head round that yet. and I have tried to round the value of the rest in the Range(cl & i).Value = y / g to two positions after the decimal pace but just keep getting errors, so post correcting by formatting column instead. If you have any tips and trick I've missed to make it better I'm open to suggestions.

    Sub WCBS_calculate_ABC_Totals_Change_Colours()

    Dim i As Long
    Dim x As Long
    Dim y As Long 'total value of case A,B,C found
    Dim g As Long 'number of times case A,B,C is found
    Dim r As Long
    Dim cl As String

    r = ActiveSheet.UsedRange.Column + ActiveSheet.UsedRange.Columns.Count 'finds the last column
    cl = Split(Cells(1, r).Address, "$")(1) 'gets the letter equivalent of the column number
    MsgBox cl
    For i = Range("A" & Rows.Count).End(3)(1).Row To 4 Step -1
    y = 0
    g = 0
    For x = 3 To r
    If Cells(1, x) = "E" Then
    Select Case Cells(i, x).Value
    Case Is = "A"
    y = y + 3
    g = g + 1
    Case Is = "B"
    y = y + 2
    g = g + 1
    Case Is = "C"
    y = y + 1
    g = g + 1
    End Select
    End If
    y = y
    Next x
    Range(cl & i).Value = y / g 'divides the total by the number of times a value is found and places it in the first column after last value in a column
    Next i

    Range("d1,f1,h1,j1,l1,n1,p1,r1,t1,v1,x1,z1,ab1,ad1,af1,ah1,aj1,al1,an1,ap1,ar1,at1,av1,ax1,az1,bb1,bd1,bf1,bh1,bj1,bl1,bn1,bp1,br1,bt1,bv1,bx1,bz1").EntireColumn.Select
    With Selection.Font
    .Name = "Calibri"
    .Size = 8
    .Color = -16777024
    End With
    Last edited by carlpots; 05-16-2014 at 11:52 AM. Reason: add xls file that would not add when tried to first post

+ 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. [SOLVED] =Subtotal(countif,Range); Subtotal and countif in 1 formula [SOLVED]
    By thomas.mapua in forum Excel General
    Replies: 5
    Last Post: 01-06-2012, 11:33 AM
  2. Combining a Date Range COUNTIF and a general COUNTIF
    By jacobtom in forum Excel General
    Replies: 1
    Last Post: 09-15-2011, 05:06 PM
  3. Adding a CountIF to a formula that is already Countif
    By Cmorgan in forum Excel General
    Replies: 4
    Last Post: 06-01-2011, 09:34 AM
  4. [SOLVED] COUNTIF or not to COUNTIF on a range in another sheet
    By Ellie in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-15-2005, 05:06 PM
  5. Countif w/ Multiple Criteria-How do I use countif
    By Patrick_KC in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-09-2005, 05:05 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