JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,707
- Office Version
- 365
- Platform
- Windows
I have a little UDF that does some tallies on a column of cells (B2:B5).
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD="align: center"]R/C[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]Group[/TD]
[TD="align: center"]Rating[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]North[/TD]
[TD="align: center"]25.2[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]South[/TD]
[TD="align: center"]14.7[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]East[/TD]
[TD="align: center"]52.0[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]West[/TD]
[TD="align: center"]33.8[/TD]
[/TR]
[TR]
[TD="align: center"]6[/TD]
[TD="align: center"]Average[/TD]
[TD="align: center"]31.4[/TD]
[/TR]
</tbody>[/TABLE]
I call the UDF from another cell like this:
I want to change that to include the cell above the first data cell (B1) and the cell after the last data cell (B6) so if I add a row, I don't have to edit the UDF call.
But I want the UDF to skip over these boundary cells. Here's my code, which works.
Is there a better way to do this?
Thanks
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD="align: center"]R/C[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]Group[/TD]
[TD="align: center"]Rating[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]North[/TD]
[TD="align: center"]25.2[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]South[/TD]
[TD="align: center"]14.7[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]East[/TD]
[TD="align: center"]52.0[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]West[/TD]
[TD="align: center"]33.8[/TD]
[/TR]
[TR]
[TD="align: center"]6[/TD]
[TD="align: center"]Average[/TD]
[TD="align: center"]31.4[/TD]
[/TR]
</tbody>[/TABLE]
I call the UDF from another cell like this:
Code:
=Tally(B2:B5)
Code:
=Tally(B1:B6)
Code:
Public Function Tally(Ratings As Range) As String
Dim cell As Range
Dim i As Integer
i = 0
For Each cell In Ratings
i = i + 1
If (i = 1) Or (i = Ratings.Count) Then
GoTo Continue
End If
. . . do the tallies . . .
Continue:
Next cell
. . . complete the calculations and return the results . . .
End Function
Thanks