Ich bin Anfängerin und programmiere für meine Masterthese und kann mir leider daher nicht erklären warum hinter "mySheet" LEER angegeben wird.
Das Problem habe ich fett markiert. Hoffe einer kann mir helfen. Vielen Dank!
Mein Code:
Public Sub Optimiere()
Dim mySheet As Worksheet
Dim highestPriceDate As Date
Set mySheet = ActiveSheet
While WorksheetFunction.Min(mySheet.Range("J:J")) 0
highestPriceDate = findHighestPriceDate(mySheet.Range("F3:F8790"), 9, 1, 3, 8790)
Call populateLevels(mySheet.Range("A3:A8790"), highestPriceDate, 1, 4, 8, 10, 11, 9)
Wend
End Sub
Private Function findHighestPriceDate(DemandPrice As Range, HydroInputCol As Integer, _
TimestampCol As Integer, startR As Long, endR As Long) As Date
Dim HighestPrice As Single
Dim HPRow As Long
Dim thisSheet As Worksheet
Dim r As Long
Dim c As Long
HighestPrice = 0
Set thisSheet = DemandPrice.Worksheet
c = DemandPrice.Column
For r = DemandPrice.Row To DemandPrice.Row + DemandPrice.Rows.Count - 1
If thisSheet.Cells(r, c) > HighestPrice And thisSheet.Cells(r, HydroInputCol) = "" Then
HighestPrice = thisSheet.Cells(r, c)
HPRow = r
End If
Next r
findHighestPriceDate = thisSheet.Cells(HPRow, TimestampCol)
End Function
Private Sub populateLevels(myRange As Range, dateToFind, TimestampCol, DemandCol, _
availableCapacityCol, ResidualOptimizationCol, generatedMWhCol, HydroInputCol)
Dim r As Long
Dim mySheet As Worksheet
Dim myMin As Single
r = myRange.Find(dateToFind).Row
Set mySheet = myRange.Worksheet
myMin = WorksheetFunction.Min(mySheet.Cells(r, DemandCol), mySheet.Cells(r, _
availableCapacityCol), mySheet.Cells(r, ResidualOptimizationCol))
mySheet.Cells(r, generatedMWhCol) = myMin
mySheet.Cells(r, HydroInputCol) = myMin
End Sub