Countif

Genetu

New Member
Joined
Apr 20, 2022
Messages
23
Office Version
  1. 2016
Platform
  1. Windows
I am new to the group. Thanks to be a member. This is my problem I want to count each needed cell value at the end of the row. Here is the image I have attached.
To be asked.PNG
In the image, the colored columns are the "counter" has to be applied. My boss wants 10 people who have more "E"s and "V"s, ("E" for Excellent & "V" for Very good. Then someone helped me. This is the code I've tried.

Sub Count_Excellents()
Dim ws As Worksheet
Dim rng As Range
Dim outputE As Range, outputV As Range

Set ws = Worksheets("Sheet1")
Set rng = ws.Range("B2:N2") 'this must be upto the end of the data range

Set outputE = ws.Range("B2").End(xlToRight).Offset(0, 1)
Set outputV = ws.Range("B2").End(xlToRight).Offset(0, 2)

outputE = Application.WorksheetFunction.CountIf(rng, "E")' for excellent
outputV = Application.WorksheetFunction.CountIf(rng, "V") 'for verygood
End Sub

Is there any one helped me by making this loop. Or any other method
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Genetu Let's get the ball rolling. Now usually my programs generate more questions than answers. But at least it starts the conversation going. Sometimes the A plus students weigh in and will give us a program with 2 lines of code. Anyway, let the discussion begin, Be sure to adjust the loop to how many time you want to loop.

VBA Code:
Sub Prog1()

Dim col As Long
Dim row As Long

col = 4
row = 2

For row = 2 To 9

Cells(row, 9) = Application.CountIf(Range(Cells(row, 4), Cells(row, 8)), "E")
Cells(row, 10) = Application.CountIf(Range(Cells(row, 4), Cells(row, 8)), "V")
Cells(row, 11) = Application.Sum(Range(Cells(row, 9), Cells(row, 10)))

Next row

End Sub

22-04-23.xlsm
ABCDEFGHIJK
1S.NoNameIDExperienceAcademicTrainingAdd LanguageApperanceExcellentVery goodTotal
2GFVEE213
3EEVPP213
4VPGEE213
5PGEEF202
6EVGFG112
7PGEEV213
8VGEEV224
9GEEFP202
Data
 
Upvote 0
Welcome to Mr. Excel.

First, please use XL2BB to illustrate the problem because no one wants to have to type your sample data.

Then, if V = very good, how can the total of the first person be 2? There are 0 Vs.
Lastly, must you do this using VBA?
 
Upvote 0
Genetu Let's get the ball rolling. Now usually my programs generate more questions than answers. But at least it starts the conversation going. Sometimes the A plus students weigh in and will give us a program with 2 lines of code. Anyway, let the discussion begin, Be sure to adjust the loop to how many time you want to loop.

VBA Code:
Sub Prog1()

Dim col As Long
Dim row As Long

col = 4
row = 2

For row = 2 To 9

Cells(row, 9) = Application.CountIf(Range(Cells(row, 4), Cells(row, 8)), "E")
Cells(row, 10) = Application.CountIf(Range(Cells(row, 4), Cells(row, 8)), "V")
Cells(row, 11) = Application.Sum(Range(Cells(row, 9), Cells(row, 10)))

Next row

End Sub

22-04-23.xlsm
ABCDEFGHIJK
1S.NoNameIDExperienceAcademicTrainingAdd LanguageApperanceExcellentVery goodTotal
2GFVEE213
3EEVPP213
4VPGEE213
5PGEEF202
6EVGFG112
7PGEEV213
8VGEEV224
9GEEFP202
Data
Thanks Ezguy, to your strive for solution. Some Problems were solved. unsolved problems are examiners are in debating to add "Age" as additional requirement. This will change the number of columns (updated weekly/monthly). The number of rows are up to last row, I already fix it by adding a variable to last row (.end(xlup)). Thanks to your immediate answer.
 
Upvote 0
Welcome to Mr. Excel.

First, please use XL2BB to illustrate the problem because no one wants to have to type your sample data.

Then, if V = very good, how can the total of the first person be 2? There are 0 Vs.
Lastly, must you do this using VBA?
to be Asked question.xlsx
ABCDEFGHIJKL
1Rate given by examiner to the candidates
2S.No.NameID ExperienceAcademicShort term trainingAdditional language skillPhysical appearanceCount "E"Count "V"
31JohnBCN/025GFGEE20
42SaraBCN/013EEVPPE= Excellent
53ChanBCN/004VPGEEV= Very good
64BruceBCN/054PGEEFG= Good
75GiliBCN/006EVGFGF= Fair
86SamBCN/018PGEEVP= Poor
97ConorBCN/068VGEEV
108AmandaBCN/009GEEEP
119BenoitBCN/016
1210AlexBCN/011
1311RachelBCN/012
1412KemalBCN/020
1513
Asked question
Cell Formulas
RangeFormula
I3I3=COUNTIF(D3:H3,"E")
J3J3=COUNTIF(D3:H3,"V")




First, I am asking apology to post my question like that. I don't know am I correct or not to upload a 'mini-sheet' using XL2BB. Anyways, I have to start with your first question. You're right the 1st person has no "V" but he has "E". To be selected, every candidate must have more than three scores of both "E &V". It may be 2:1, 3:0, or 3:2, etc... For your last question, the easiest solution is VBA. Because the candidates are more than 3600 from different branches.
 
Upvote 0
I could do this all day long. Here is my second round of solutions. Now with this one you have to make sure the A column equals the last data entry. Also if you want that formula in I3, J3 & total in K3, let us know. Now if you are happy with just the answer, also let us know.

VBA Code:
Sub Prog1A()

Dim n As Long
Dim col As Long
Dim row As Long
Dim LastCell As Long

LastCell = Cells(Rows.Count, "A").End(xlUp).row
col = 4

For row = 3 To LastCell

Cells(row, 9) = Application.CountIf(Range(Cells(row, 4), Cells(row, 8)), "E")
Cells(row, 10) = Application.CountIf(Range(Cells(row, 4), Cells(row, 8)), "V")
Cells(row, 11) = Application.Sum(Range(Cells(row, 9), Cells(row, 10)))

Next row

End Sub



22-04-23 rev a.xlsm
ABCDEFGHIJKL
1Rate given by examiner to the candidates
2S.No.NameIDExperienceAcademicShort term trainingAdditional language skillPhysical appearanceCount "E"Count "V"Total Points
31JohnBCN/025GFGEE202
42SaraBCN/013EEVPP213E= Excellent
53ChanBCN/004VPGEE213V= Very good
64BruceBCN/054PGEEF202G= Good
75GiliBCN/006EVGFG112F= Fair
86SamBCN/018PGEEV000P= Poor
97ConorBCN/068VGEEV224
108AmandaBCN/009GEEEP303
119BenoitBCN/016PGEEF202
1210AlexBCN/011EVGFG112
1311RachelBCN/012PGEEV213
1412KemalBCN/020VGEEV224
Sheet1
 
Upvote 0
Solution
I could do this all day long. Here is my second round of solutions. Now with this one you have to make sure the A column equals the last data entry. Also if you want that formula in I3, J3 & total in K3, let us know. Now if you are happy with just the answer, also let us know.

VBA Code:
Sub Prog1A()

Dim n As Long
Dim col As Long
Dim row As Long
Dim LastCell As Long

LastCell = Cells(Rows.Count, "A").End(xlUp).row
col = 4

For row = 3 To LastCell

Cells(row, 9) = Application.CountIf(Range(Cells(row, 4), Cells(row, 8)), "E")
Cells(row, 10) = Application.CountIf(Range(Cells(row, 4), Cells(row, 8)), "V")
Cells(row, 11) = Application.Sum(Range(Cells(row, 9), Cells(row, 10)))

Next row

End Sub



22-04-23 rev a.xlsm
ABCDEFGHIJKL
1Rate given by examiner to the candidates
2S.No.NameIDExperienceAcademicShort term trainingAdditional language skillPhysical appearanceCount "E"Count "V"Total Points
31JohnBCN/025GFGEE202
42SaraBCN/013EEVPP213E= Excellent
53ChanBCN/004VPGEE213V= Very good
64BruceBCN/054PGEEF202G= Good
75GiliBCN/006EVGFG112F= Fair
86SamBCN/018PGEEV000P= Poor
97ConorBCN/068VGEEV224
108AmandaBCN/009GEEEP303
119BenoitBCN/016PGEEF202
1210AlexBCN/011EVGFG112
1311RachelBCN/012PGEEV213
1412KemalBCN/020VGEEV224
Sheet1
Ezguy4u, I admire your motivation to solve members' problems. I appreciate it. I modified your code to the last row and last column. But I need you to take the fame(prize). Did I violate the group rule?
 
Upvote 0
Genetu I don't know all the rules here, but I figure we are doing ok. I was thinking, maybe we should put Application.ScreenUpdating = False at the top and Application.ScreenUpdating = True at the bottom. If you have lots of rows, this will stop the screen from updating. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,818
Messages
6,121,725
Members
449,049
Latest member
MiguekHeka

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top