tjdickinson
Board Regular
- Joined
- Jun 26, 2021
- Messages
- 61
- Office Version
- 365
- Platform
- Windows
I have a userform that takes input from the user and adds it to the first five rows in the next available column of the worksheet.
In row 6, I want a formula like:
but the cell reference, of course, has to be for the current column (which changes with each instance of the userform).
I'm making a gradebook, and the row in question is giving the class average result of the given assignment. Thus, in (ex.) D7:D32, the user adds the student's scores, and D6 calculates the average of those scores. The cells in the range are completely empty (including no functions/formulas), so blank cells should be ignored. (Of course, zeros should not be ignored.) The class average cell (in row 6) should appear blank until the user adds values in the range below it.
I currently have this code:
So far, I've tried the following code in the indicated position:
but none of them work.
Any ideas, suggestions, or solutions very much welcome.
In row 6, I want a formula like:
Excel Formula:
=IFERROR(AVERAGE(D7:D32),"")
I'm making a gradebook, and the row in question is giving the class average result of the given assignment. Thus, in (ex.) D7:D32, the user adds the student's scores, and D6 calculates the average of those scores. The cells in the range are completely empty (including no functions/formulas), so blank cells should be ignored. (Of course, zeros should not be ignored.) The class average cell (in row 6) should appear blank until the user adds values in the range below it.
I currently have this code:
VBA Code:
Private Sub Add_Eval_Add_Click()
Dim iCol As Long
Dim ws As Worksheet
Set ws = Worksheets("Gradebook")
'find first empty column in database
iCol = ws.Cells.Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column + 1
'irrelevant code removed for brevity
With ws
' .Unprotect Password:="password"
.Cells(1, iCol).Value = Me.Eval_Title.Value
.Cells(2, iCol).Value = Me.Eval_Cat.Value
.Cells(3, iCol).Value = Me.Eval_Date.Value
.Cells(3, iCol).NumberFormat = "dd/mm"
.Cells(4, iCol).Value = Me.Eval_Due_Date.Value
.Cells(4, iCol).NumberFormat = "dd/mm"
.Cells(5, iCol).Value = Me.Eval_Points.Value
.Cells(5, iCol).NumberFormat = "##0.0"
' Here's where I want to add the average function
.Cells(6, iCol).NumberFormat = "##0.0"
' .Protect Password:="password"
End With
End Sub
So far, I've tried the following code in the indicated position:
VBA Code:
.Cells(6, iCol).Value = Application.Average(Range((7, iCol), (32, iCol)))
VBA Code:
.Cells(6, iCol).Formula = "=IFERROR(AVERAGE(D7:D32),"")"
VBA Code:
.Cells(6, iCol).Value = "=IFERROR(AVERAGE(D7:D32),"")"
Any ideas, suggestions, or solutions very much welcome.