Thema Datum  Von Nutzer Rating
Antwort
13.05.2014 17:08:59 Gast9241
Solved
13.05.2014 17:44:57 Gast27593
NotSolved
14.05.2014 11:06:34 Gast44320
NotSolved
14.05.2014 12:24:48 Gast97928
NotSolved
14.05.2014 14:55:54 Gast60942
NotSolved
14.05.2014 15:49:22 Gast51899
NotSolved
17.05.2014 09:53:22 Gast29035
NotSolved
17.05.2014 11:49:38 Gast82195
NotSolved
Rot Gleitender Durchschnitt
17.05.2014 20:38:42 Gast96071
NotSolved
20.05.2014 18:34:06 Gast8649
NotSolved
20.05.2014 21:41:59 Gast12012
NotSolved
20.05.2014 22:27:03 Gast97120
NotSolved
21.05.2014 00:38:42 Gast88349
NotSolved
21.05.2014 00:39:11 Gast21760
NotSolved
21.05.2014 08:57:32 Gast5621
NotSolved
21.05.2014 10:10:56 Gast3523
NotSolved
21.05.2014 16:13:44 Gast27780
NotSolved
21.05.2014 16:22:50 Gast65966
NotSolved
21.05.2014 17:04:46 Gast92787
NotSolved
21.05.2014 20:10:03 Gast75535
NotSolved
22.05.2014 14:49:31 Gast60006
NotSolved
14.05.2014 11:06:54 Gast60815
NotSolved
14.05.2014 11:06:54 Gast91131
NotSolved
14.05.2014 11:06:55 Gast53841
NotSolved

Ansicht des Beitrags:
Von:
Gast96071
Datum:
17.05.2014 20:38:42
Views:
1014
Rating: Antwort:
  Ja
Thema:
Gleitender Durchschnitt

Ok, ich sehe du hast dir Gedanken dazu gemacht.

Hier mal meine Lösung (auf einem leeren Tabellenblatt testen / ausführen):

Geh es mal für dich gedanklich durch (es ähnelt deiner Herangehensweise).

Option Explicit

Sub Test()
  
  Dim wks As Excel.Worksheet
  Dim rng As Excel.Range
  Dim lngLastRow As Long
  
  Set wks = ThisWorkbook.Worksheets("Tabelle1")
  
  With wks
    
  '>> Beispieldaten erzeugen >>
    With .Range("A1:A1200")
      .NumberFormat = "General"
      .Formula = "=RANDBETWEEN(100,1000)"
      .Value = .Value 'Formeln zu Werten
    End With
  '<<
    
    'letzte Zelle mit Wert in Spalte A suchen
    '(hier nur zur Demonstation, wir wissen ja bereits die Anzahl der Spalte)
    lngLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    'den zu betrachenden Bereich referenzieren
    Set rng = .Range(.Cells(1, "A"), .Cells(lngLastRow, "A"))
    
  End With
  
  With rng
    'Ausgabe erfolgt in der Spalte daneben
    With .Offset(ColumnOffset:=1)
      .NumberFormat = "0.000"
      .Value = SMA(rng, 60) 'gleitenden Mittelwert im Intervall = 60 berechnen / ausgeben
    End With
  End With
  
End Sub

'//////////////////////////////////////////////////
'// Simple Moving Average
Public Function SMA(ValueList As Excel.Range, Interval As Long) As Variant
  
  If ValueList.Rows.Count > 1 Eqv ValueList.Columns.Count > 1 Then
  'matrix not allowed
    SMA = CVErr(XlCVError.xlErrRef)
    Exit Function
  ElseIf Not (2 <= Interval And Interval <= ValueList.Cells.Count) Then
  'interval out of range
    SMA = CVErr(XlCVError.xlErrNum)
    Exit Function
  End If
  
  Dim rngCell As Excel.Range
  Dim avntSMA() As Variant
  Dim dblSum As Double
  Dim i As Long
  
  ReDim avntSMA(1 To ValueList.Cells.Count)
  
  On Error GoTo ErrNotNumeric
    For i = 1 To ValueList.Cells.Count
      dblSum = dblSum + CDbl(ValueList.Cells(i).Value)
      If i >= Interval Then
        avntSMA(i) = dblSum / CDbl(Interval)
        dblSum = dblSum - CDbl(ValueList.Cells(1 + i - Interval).Value)
      Else
        avntSMA(i) = CVErr(XlCVError.xlErrNA)
      End If
    Next
  On Error GoTo 0
  
SafeExit:
  
  If ValueList.Rows.Count > ValueList.Columns.Count Then
    SMA = WorksheetFunction.Transpose(avntSMA)
  Else
    SMA = avntSMA
  End If
  
  Erase avntSMA
  
Exit Function
  
ErrNotNumeric:
  For i = i To ValueList.Cells.Count
    avntSMA(i) = CVErr(XlCVError.xlErrValue)
  Next
  GoTo SafeExit
End Function

 


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
13.05.2014 17:08:59 Gast9241
Solved
13.05.2014 17:44:57 Gast27593
NotSolved
14.05.2014 11:06:34 Gast44320
NotSolved
14.05.2014 12:24:48 Gast97928
NotSolved
14.05.2014 14:55:54 Gast60942
NotSolved
14.05.2014 15:49:22 Gast51899
NotSolved
17.05.2014 09:53:22 Gast29035
NotSolved
17.05.2014 11:49:38 Gast82195
NotSolved
Rot Gleitender Durchschnitt
17.05.2014 20:38:42 Gast96071
NotSolved
20.05.2014 18:34:06 Gast8649
NotSolved
20.05.2014 21:41:59 Gast12012
NotSolved
20.05.2014 22:27:03 Gast97120
NotSolved
21.05.2014 00:38:42 Gast88349
NotSolved
21.05.2014 00:39:11 Gast21760
NotSolved
21.05.2014 08:57:32 Gast5621
NotSolved
21.05.2014 10:10:56 Gast3523
NotSolved
21.05.2014 16:13:44 Gast27780
NotSolved
21.05.2014 16:22:50 Gast65966
NotSolved
21.05.2014 17:04:46 Gast92787
NotSolved
21.05.2014 20:10:03 Gast75535
NotSolved
22.05.2014 14:49:31 Gast60006
NotSolved
14.05.2014 11:06:54 Gast60815
NotSolved
14.05.2014 11:06:54 Gast91131
NotSolved
14.05.2014 11:06:55 Gast53841
NotSolved