Need help on vba code/excel formula to use!

ynyend1

New Member
Joined
Jul 12, 2013
Messages
12
Office Version
  1. 2019
Platform
  1. Windows
Hello all
Greetings!
I have attached a workbook here containing sample data and clear explanation of what I need.
This is what I want to achieve:

I need an Excel formula/VBA Code that will do the following:
1: Concatenate the SUBJECT NAME in the average results with the DYANAMIC LETTER GRADE which will change automatically as average marks changes for each subject as per the criteria given in column AO and AP.. Refer to the combined results column in the attached workbook for the output I want; then:
2: If the student does not take any of the above subjects then it should not concatenate that particular subject with its marks, it should leave it blank and proceed to the next subject; refer to the second student in the attached sheet (check the combined result for the second students, that's the output I want).

I will highly appreciate for your help!

SAMPLE FILE FOR FORMULA HELP.xlsx
AA
339
Sheet1
Cell Formulas
RangeFormula
AA3AA3=IFERROR(AVERAGE(C3,O3),"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A3:AK4Expression=$A3=""textNO
Cells with Data Validation
CellAllowCriteria
B3:B4ListME,KE
C3:AK4Whole numberbetween 0 and 100
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Please show example Desired Result on Sheet Then Select All your Range Then Upload it with XL2BB ADDIN.
 
Upvote 0
SAMPLE FILE FOR FORMULA HELP.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAY
1MID TERMTERMINALAVERAGE RESULTSCRITERIAI need a formula that will do the following: 1: Concatenate the SUBJECT NAME in the average results with the DYANAMIC LETTER GRADE which will change automatically as average marks changes for each subject as per the criteria given in column AO and AP.. Refer to the combined results column in the attached sheet for the output I want; then: 2: If the student does not take any of the above subjects then it should not concatenate that particular subject with its marks, it should leave it blank and proceed to the next subject as it is seen for the second student in the attached sheet (check the combined result for the second students, that;s the output I want).
2STUDENT NAMEJINSIACIVICSHISTORYGEOGRAPHYKISWAHILIENGLISHPHYSICSCHEMISTRYBIOLOGYB/MATHSARABICDINIColumn1CIVICS HISTORY GEOGRAPHY KISWAHILI ENGLISH PHYSICS CHEMISTRY BIOLOGY B/MATHS ARABIC DINI Column2CIVHISGEOKISWENGPHYCHEMBIOLB/MATHARABIC DINI COMBINED RESULTSLETTER GRADEFROMTO
3ASHURA RAMADHANIME234354656567345687988854892065432522459043653966376554462851897177CIV-'D', HIST-'B', GEO-'D', KISW-'B', ENGL-'C', PHY-'C', CHEM-'F', BIO-'C', B/MATH-'A', ARABIC -'B', DINI -'A'A75100
4KESIA SHADRACKKE456787877654433456677656896740 627782 667255  CIV-'D', GEO-'C', KISW-'A', ENGL-'A', CHEM-'B', BIO-'B', B/MATH-'C'B6574
5C4564
6D3044
7F029
Sheet1
Cell Formulas
RangeFormula
AE2:AF2,AA2:AC2AA2=LEFT(O2,3)
AD2,AG2:AH2AD2=LEFT(R2,4)
AI2AI2=LEFT(W2,6)
AJ2:AK2AJ2=LEFT(X2,7)
AA3:AK4AA3=IFERROR(AVERAGE(C3,O3),"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
AL3:AL4Expression=$A3=""textNO
A3:AK4Expression=$A3=""textNO
Cells with Data Validation
CellAllowCriteria
B3:B4ListME,KE
C3:AK4Whole numberbetween 0 and 100
 
Upvote 0
Try This VBA Code:
VBA Code:
Sub AddCombinedResults()
Dim i As Long, j As Long, Lr As Long, R As String, S As String
Lr = Range("A" & Rows.Count).End(xlUp).Row
For i = 3 To Lr
For j = 27 To 37
If Cells(i, j).Value = "" Then
Else
R = Application.WorksheetFunction.Index(Range("AN3:AN7"), Application.WorksheetFunction.Match(Cells(i, j), Range("Ap3:AP7"), -1))
R = Cells(2, j).Value & "-'" & R & "'"
If S = "" Then
S = R & ", "
Else
S = S & R & ", "
End If
End If
Next j
Cells(i, 38).Value = Left(S, Len(S) - 2)
S = ""
Next i
End Sub
 
Upvote 0
Solution
Try This VBA Code:
VBA Code:
Sub AddCombinedResults()
Dim i As Long, j As Long, Lr As Long, R As String, S As String
Lr = Range("A" & Rows.Count).End(xlUp).Row
For i = 3 To Lr
For j = 27 To 37
If Cells(i, j).Value = "" Then
Else
R = Application.WorksheetFunction.Index(Range("AN3:AN7"), Application.WorksheetFunction.Match(Cells(i, j), Range("Ap3:AP7"), -1))
R = Cells(2, j).Value & "-'" & R & "'"
If S = "" Then
S = R & ", "
Else
S = S & R & ", "
End If
End If
Next j
Cells(i, 38).Value = Left(S, Len(S) - 2)
S = ""
Next i
End Sub
This is Great! It works perfectly!
Be blessed abundantly!!
 
Upvote 0
I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’).

For example, if you have Excel 365 and were interested in a formula solution, you could try this.

ynyend1.xlsm
AAABACADAEAFAGAHAIAJAKALAMANAOAP
1AVERAGE RESULTSCRITERIA
2CIVHISGEOKISWENGPHYCHEMBIOLB/MATHARABIC DINI COMBINED RESULTSLETTER GRADEFROMTO
338.566376554462850.588.570.576.5CIV-'D', HIS-'B', GEO-'D', KISW-'B', ENG-'C', PHY-'C', CHEM-'F', BIOL-'C', B/MATH-'A', ARABIC -'B', DINI -'A'A75100
439.561.57781.56671.555CIV-'D', GEO-'C', KISW-'A', ENG-'A', CHEM-'B', BIOL-'B', B/MATH-'C'B6574
5C4564
6D3044
7F029
Sheet1
Cell Formulas
RangeFormula
AL3:AL4AL3=TEXTJOIN(", ",1,IF(AA3:AK3="","",AA$2:AK$2&"-'"&XLOOKUP(AA3:AK3,AO$3:AO$7,AN$3:AN$7,"",-1,-1)&"'"))
 
Upvote 0
You're Welcome & Please upload your Account Details as Peter_SSs Said.
Thanks for Feedback also.
 
Upvote 0
Try This VBA Code:
VBA Code:
Sub AddCombinedResults()
Dim i As Long, j As Long, Lr As Long, R As String, S As String
Lr = Range("A" & Rows.Count).End(xlUp).Row
For i = 3 To Lr
For j = 27 To 37
If Cells(i, j).Value = "" Then
Else
R = Application.WorksheetFunction.Index(Range("AN3:AN7"), Application.WorksheetFunction.Match(Cells(i, j), Range("Ap3:AP7"), -1))
R = Cells(2, j).Value & "-'" & R & "'"
If S = "" Then
S = R & ", "
Else
S = S & R & ", "
End If
End If
Next j
Cells(i, 38).Value = Left(S, Len(S) - 2)
S = ""
Next i
End Sub
Hello, This formula worked perfectly in the sheet you attached, but when I apply it to other sheets I have for other classes I get the RESULTS correctly but with the following error message as attached in the image
1620465444810.png


What am I missing here?
Furthermore, is there a way that I can make a Button that will run the code throughout all my sheets named "FORM I, FORM II, FORM III, FORM IV"?
Please assist this one!
Thanks in advance!
 
Upvote 0
Thanks for updating your profile. (y)

If you turned your criteria columns up the other way, might this formula work for you?

ynyend1.xlsm
AAABACADAEAFAGAHAIAJAKALAMANAOAP
1AVERAGE RESULTSCRITERIA
2CIVHISGEOKISWENGPHYCHEMBIOLB/MATHARABICDINICOMBINED RESULTSLETTER GRADEFROMTO
338.566376554462850.588.570.576.5CIV-'D', HIS-'B', GEO-'D', KISW-'B', ENG-'C', PHY-'C', CHEM-'F', BIOL-'C', B/MATH-'A', ARABIC-'B', DINI-'A'F029
439.561.57781.56671.555CIV-'D', GEO-'C', KISW-'A', ENG-'A', CHEM-'B', BIOL-'B', B/MATH-'C'D3044
5C4564
6B6574
7A75100
Sheet3
Cell Formulas
RangeFormula
AL3:AL4AL3=TEXTJOIN(", ",1,IF(AA3:AK3="","",AA$2:AK$2&"-'"&INDEX(AN$3:AN$7,MATCH(AA3:AK3,AO$3:AO$7))&"'"))
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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