I am setting up an excel worksheet to automatically populate office rotations for an incoming class of graduate students. The input will be their choices of professors and the number of open seats the professors have. I want to update the value of the number of open seats the professors have as I assign a rotation slot to each student, but the code seems to be breaking when I attempt to assign a value to a cell outside that of the calling cell.
I have tried switching between subs and functions to no avail. It seems as though VBA simply does not allow changing the value of a cell from a different cell. Is this true?
Sub DecrementSeats(PIName As String, RotNum As Integer)
Dim i As Integer, seats As Integer
Dim c As Range
seats = 0
i = 2
MsgBox ("In decrement")
For Each c In Worksheets("Student Interest and Rotations").Range("A2:A41")
If c.Value = PIName Then
MsgBox (c.Value & " is the same as " & PIName)
seats = c.Offset(0, (1 + RotNum)).Value
MsgBox ("Original seats value is: " & seats)
seats = seats - 1
c.Offset(0, (1 + RotNum)) = seats
MsgBox ("New c.Value value is: " & c.Offset(0, (1 + RotNum)).Value)
Exit For
End If
MsgBox (c.Value & " is not the same as " & PIName & ". Checking next PI name...")
Next c
End Sub