JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,691
- Office Version
- 365
- Platform
- Windows
I would like to write a UDF that will examine the contents of each cell in a named array and return various results. The array contains the scores of tennis matches between players on a club tennis ladder. Here's an example:
[TABLE="class: grid, width: 349"]
<tbody>[TR]
[TD="align: center"]R/C[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]G[/TD]
[/TR]
[TR]
[TD="align: center"]13[/TD]
[TD="align: center"]Winner[/TD]
[TD="align: center"]Loser[/TD]
[TD="align: center"]Set1[/TD]
[TD="align: center"]Set2[/TD]
[TD="align: center"]Set3[/TD]
[/TR]
[TR]
[TD="align: center"]14[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]6-3[/TD]
[TD="align: center"]4-6[/TD]
[TD="align: center"]6-2[/TD]
[/TR]
[TR]
[TD="align: center"]15[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]6-1[/TD]
[TD="align: center"]7-5[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]16[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]6-4[/TD]
[TD="align: center"]6-4[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]17[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]3-6[/TD]
[TD="align: center"]7-5[/TD]
[TD="align: center"]7-5[/TD]
[/TR]
[TR]
[TD="align: center"]18[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]6-1[/TD]
[TD="align: center"]6-4[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]19[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]7-6[/TD]
[TD="align: center"]7-6[/TD]
[TD="align: center"][/TD]
[/TR]
</tbody>[/TABLE]
Assume that the range C14:G19 is assigned the name "Results", I would like help writing the skeleton of a loop that will allow me to process the data in each row. I envision something like this:
Can someone help me with the correct syntax for the For loop and for accessing the contents of the cells inside the loop?
The Options parameter will tell the UDF what results to return.
Thanks
[TABLE="class: grid, width: 349"]
<tbody>[TR]
[TD="align: center"]R/C[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]G[/TD]
[/TR]
[TR]
[TD="align: center"]13[/TD]
[TD="align: center"]Winner[/TD]
[TD="align: center"]Loser[/TD]
[TD="align: center"]Set1[/TD]
[TD="align: center"]Set2[/TD]
[TD="align: center"]Set3[/TD]
[/TR]
[TR]
[TD="align: center"]14[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]6-3[/TD]
[TD="align: center"]4-6[/TD]
[TD="align: center"]6-2[/TD]
[/TR]
[TR]
[TD="align: center"]15[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]6-1[/TD]
[TD="align: center"]7-5[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]16[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]6-4[/TD]
[TD="align: center"]6-4[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]17[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]3-6[/TD]
[TD="align: center"]7-5[/TD]
[TD="align: center"]7-5[/TD]
[/TR]
[TR]
[TD="align: center"]18[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]6-1[/TD]
[TD="align: center"]6-4[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]19[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]7-6[/TD]
[TD="align: center"]7-6[/TD]
[TD="align: center"][/TD]
[/TR]
</tbody>[/TABLE]
Assume that the range C14:G19 is assigned the name "Results", I would like help writing the skeleton of a loop that will allow me to process the data in each row. I envision something like this:
Code:
Function Tally(Results As Range, Options As String)
...initial code
For Each Row In Results
...initial code for each row
Winner = ???
Loser = ???
Set1 = ???
Set2 = ???
Set3 = ???
...calculations on data
Next Row
...cleanup & results
End Function
Can someone help me with the correct syntax for the For loop and for accessing the contents of the cells inside the loop?
The Options parameter will tell the UDF what results to return.
Thanks