I tried to simplify my needs and decided, instead of creating a function, that a regular macro could also do it.
Instead of having the building and the heat as parameter, I took the cogeneration unit. I am then filling a table with where one column is the cogeneration unit (fixed list) and the other is the calculated runningtime.
Sub RunningTime()
Dim i As Integer
Dim cogen As String
cogen = Worksheets("Berechnung").range("G4").Formula 'Backup of the current bhkw
i = 0 'vertical offset = 0
'Fill the table
Do
Worksheets("Berechnung").range("G4") = Worksheets("Berechnung").range("AJ10").offset(i, 0)
Calculate
Worksheets("Berechnung").range("AJ10").offset(i, 1) = Worksheets("Berechnung").range("I34") 'value in next column equals running time
i = i + 1
Loop Until IsEmpty(Worksheets("Berechnung").range("AJ10").offset(i, 0))
'Restore backup
Worksheets("Berechnung").range("G4") = cogen
End Sub
Bookmarks