Hallo liebe VBA-Experten,
seit ca. 2 Tagen versuche ich ein Ergebnis aus einer Unterprozedur in meine Hauptprozedur zu bekommen.
Ich kriege das einfach nicht hin.
Ich muss dazu sagen, dass ich von VBA eigentl keine Ahnung habe und das gesamte Programm mittels Internet und irgendwelchen alten Aufzeichnungen erstellt habe.
Also folgendes:
Option Explicit
Sub fonds(m As Integer, my As Double, sigma As Double, sparbeitrag As Double, pfad() As Double)
Dim endvermögen As Double
Dim i As Integer
Dim fondsindex As Double
Dim s As Double
ReDim pfad(0 To m)
s = 1
fondsindex = 1
For i = 1 To m
fondsindex = fondsindex * Exp(my + sigma * Application.WorksheetFunction.NormSInv(Rnd()))
pfad(i) = s + (1 / fondsindex)
s = pfad(i)
Next i
endvermögen = sparbeitrag * (s - fondsindex) * fondsindex
End Sub
Bis hier funktioniert das Programm einwandfrei und es wird alles korrekt berechnet!!
Nun möchte ich dieses ENDVERMÖGEN als Ergebnis in das Hauptprogramm übertragen:
Sub fonds1()
Const tabname = "fonds1"
Dim j As Integer
Dim abzeile, inspalte As Integer
Dim m As Integer
Dim my As Double
Dim sigma As Double
Dim sparbeitrag As Double
Dim endvermögen As Double
Dim s As Double
Dim fondsindex As Double
Dim pfad() As Double
Application.ScreenUpdating = False 'bildschirminhalte werden nicht aktualisiert
abzeile = 10
inspalte = 4
Worksheets(tabname).Range(Cells(abzeile, inspalte), Cells(abzeile + 10000, inspalte)).ClearContents
m = Worksheets(tabname).Cells(4, 2).Value
my = Worksheets(tabname).Cells(5, 2).Value
sigma = Worksheets(tabname).Cells(6, 2).Value
sparbeitrag = Worksheets(tabname).Cells(3, 2).Value
For j = 1 To 10000 '10000 simulationen
Call fonds(m, my, sigma, sparbeitrag, pfad) ??IST DAS RICHTIG??
Worksheets(tabname).Cells(abzeile + j, inspalte).Value =???
WAS MUSS HIER STEHEN, DAMIT DAS ERGEBNIS ÜBERNOMMEN WIRD??
Next j
Application.ScreenUpdating = True aktualisiert
Calculate
End Sub
Bin jeder Hilfe ohne Ende dankbar!!!
|