so I am attempting to write a function in VBA which will read the value of a cell (CE4) in another spreadsheet and if that value is equal to "Denied", then it will read the value of CE5 and on and on until it reaches a cell in column CE where the value is "Approved", at which point it will output the value of another cell in the same row (in column B). The idea is that I will input the cell references for the starting cells into the formula and if the initial value for CE is "Denied" it will do the process I described above, otherwise it will output the value for the corresponding cell in column B. I have the following code:
Function transfer(ApplicationCell As String, ConditionCell As String) As String
Dim i As Integer
i = 1
With Worksheets("Application Report")
If .Range(ConditionCell).Value = "Denied" Then
Do While .Range(ConditionCell).Value = "Denied"
.Range(ConditionCell).Value = .Range(ConditionCell).Offset(i, 0).Value
.Range(ApplicationCell).Value = .Range(ApplicationCell).Offset(i, 0).Value
i = 1 + 1
Loop
End If
transfer = .Range(ApplicationCell).Value
End With
End Function
The initial value for ApplicationCell is B4 and the initial value for ConditionCell is CE4. However, whenever I attempt to input the values into the function, I get #VALUE!. I know I'm doing something wrong but I am new to VBA so I am unsure of where I am going wrong. Any help would be appreciated!