PRAVEEN T
asked on
Need help on Excel Macro to get sum,avg and result
ASKER
Hi,
I have the excel sheet with the following columns
studentID
Mark_1
Mark_2
Mark_3
Total
AVG
Result
I need a macro that can get values ( Mark_1,2,3) from the sheet and update the Total , Average and Result
Result :: Pass/Fail
If avegrate < 50 then fail else pass
Pass - column should fill with green
Fail - Column should fill with red..
All things need to done in the macro only...
Thanks
I have the excel sheet with the following columns
studentID
Mark_1
Mark_2
Mark_3
Total
AVG
Result
I need a macro that can get values ( Mark_1,2,3) from the sheet and update the Total , Average and Result
Result :: Pass/Fail
If avegrate < 50 then fail else pass
Pass - column should fill with green
Fail - Column should fill with red..
All things need to done in the macro only...
Thanks
how do you want to call the macro, a button or on enter of a cell, or on open of the worksheet?
are you familiar with Pivot tables?
or you could use calculated functions on necessary cells.
ASKER
I need to call this macro with button click
Shums approach is exactly where I was going. It is the best approach.
K
K
ASKER
I know we can do it by aggregate function with excel provided , But we are working on the reports where we are getting table data to excel...in the macro we need to handle these things.. user dont need to select from the excel shseet. ( Ijust want to automate this process)
Ok Try below Macro:
Hope you have Sheet name as "Test", and columns headers are same:
Praveen_Formula_v2.xlsm
Hope you have Sheet name as "Test", and columns headers are same:
Sub UpdateResult()
Dim Ws As Worksheet
Application.ScreenUpdating = False
Set Ws = Worksheets("Test")
With Ws.ListObjects(1)
.ListColumns("Total").DataBodyRange.FormulaR1C1 = "=SUM(Table1[@[Mark_1]:[Mark_3]])"
.ListColumns("AVG").DataBodyRange.FormulaR1C1 = "=AVERAGE(Table1[@[Mark_1]:[Mark_3]])"
.ListColumns("Result").DataBodyRange.FormulaR1C1 = "=IF([@AVG]<50,""Fail"",""Pass"")"
End With
With Ws.ListObjects(1).ListColumns("Result").DataBodyRange
.FormatConditions.Delete
.FormatConditions.Add xlCellValue, Operator:=xlEqual, Formula1:="=""Pass"""
.FormatConditions(1).Interior.Color = RGB(0, 192, 0)
.FormatConditions.Add xlCellValue, Operator:=xlEqual, Formula1:="=""Fail"""
.FormatConditions(2).Interior.Color = RGB(255, 0, 0)
End With
Application.ScreenUpdating = True
End Sub
Try in attached first before applying on your original.Praveen_Formula_v2.xlsm
ASKER
Thank you . this is working fine.
I need a small change on that. Can we add the range that user can enter the value then click on the button.. the macro is going to update the those rows that user entered.
Example::
If the user enter the student ID 1 to 5... then only those records need to update with the macro...
Can we do this
Thank you.
I need a small change on that. Can we add the range that user can enter the value then click on the button.. the macro is going to update the those rows that user entered.
Example::
If the user enter the student ID 1 to 5... then only those records need to update with the macro...
Can we do this
Thank you.
Are you gonna have table range or cell range?
If its gonna be table range, then it would be difficult.
If its gonna be table range, then it would be difficult.
ASKER
Cell range.. like student id..1 to 5
In your initial sample you provided with Table, will that range be Table Range or Normal Range?
ASKER
Its normal range
Sorry then I would request you to close this question and raise another question. Above vba I provided was for Table Range which you asked initially and provided sample with Table Range.
ASKER
Sure
ASKER
Hi ,
I have raise the new case .. Can you please help me on this ... Thank you
I have raise the new case .. Can you please help me on this ... Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
You're welcome Praveen! Glad I was able to help.
Your second question is also answered, try and close that as well.
Your second question is also answered, try and close that as well.
Need details, please.