To alleviate my summer boredom, I decided to try to make an Excel program that keeps track of how much money someone would owe based on properties owned and number of houses on those properties in the board game Monopoly (some new rules I'm experimenting with). I set up the spreadsheet such that every property is in its own row. I want the Excel program to do this:
Let's say you're looking at a cell. Then, For i=1 To 10 (since I doubt more than 10 players in Monopoly is feasible), if the value of the cell to the right is i, then add the value of the cell you're actually looking at to a sum for player i.
Can I generate variables variables sum1, sum2, sum3, ... , sum10? And then can I say something like
sum'i' = sum'i' + cell.Value
within a for loop if the condition in paragraph 2 is met?
UPDATE: I have tried this code, and it works in getting Player 1's sum. However, it gives Player 1's sum for all players, and it's cumbersome to update whenever someone buys new property or upgrades current property (I need to re-type the formula with each update).
Public Function monopolySum(i As Integer) As Variant
Dim sum(1 To 10) As Variant, rng As Range, cell As Range
For i = 1 To 10
sum(i) = 0
Next i
Set rng = Range("C2:C29")
For Each cell In rng
For i = 1 To 10
If cell.Offset(0, 1).Value = i Then
sum(i) = sum(i) + cell.Value
End If
Next i
Next cell
For i = 1 To 10
monopolySum = sum
Next i
End Function
Thanks in advance everyone! I have very little experience programming and would greatly appreciate any guidance :)