After lots of help from mikerickson on cell adjacency, I'm back with another problem..!
I have a workbook with several sheets, some with fixed cell values and some with values that change.
I've adapted a code from mikerickson that allows me to create a UDF called lighttest which looks at the value of a cell and then takes one of several options.
Function lighttest (ByVal mastercell As Range) As Double
Application.Volatile
If mastercell.Value = 3 Then
lighttest = WorksheetFunction.Sum(masterCell.Value, Worksheets ("daylight input").[A1])
Else
If masterCell.Value = 2 Then
lighttest = masterCell.Value
Else
If masterCell.Value = 1 Then
lighttest = WorksheetFunction.Sum(masterCell.Value, 5)
End If
End If
End If
End Function
The code works fine as it is but I'd like to change the option for the value 3, so that it sums the active cell on the main sheet 'mastergrid' with the same cell on the sheet 'daylight input' (rather than cell A1), and ideally, the same cell on other worksheets too.
I tried replacing [A1] with [masterCell] but I keep getting #VALUE! errors
Any help would be gratefully received
Bookmarks