Excel: Wie gestalte ich dieses Makro schneller und effektiver und sorge dafür, dass es bei Neustart nur neue Werte erkennt?
Wie kann ich dieses Makro schneller und effektiver machen und wie bekomme ich es hin, dass es beim Neustart nicht schon wieder die Werte erkennt, die schon einmal dran waren? Sodass die 50 nach dem ersten Mal Abspielen des Sounds ignoriert wird.
Code:
Sub PlaySound()
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
Dim goals As Long
Dim soundFile As String
Dim thresholds As Variant
Dim i As Integer
Set ws = ThisWorkbook.Worksheets("Spielplan")
Set rng = ws.Range("O1:O" & ws.Cells(ws.Rows.Count, "O").End(xlUp).row)
soundFile = "Sound_pfad.mp3"
'Array of threshold values
thresholds = Array(50, 100, 150, 200, 250, 300, 350, 400, 450, 500,550,600,650,700,750,800,850,900,950,1000)
Do While True 'Endlosschleife hinzugefügt
For Each cell In rng
If IsNumeric(cell.Value) Then
goals = goals + cell.Value
'Check if goals is equal to any of the threshold values
For i = LBound(thresholds) To UBound(thresholds)
If goals = thresholds(i) Then
Application.ScreenUpdating = False
Application.EnableEvents = False
ActiveSheet.OLEObjects.Add(Filename:=soundFile, Link:=False, DisplayAsIcon:=False).Select
Selection.Verb Verb:=xlPrimary
Selection.Delete
Application.ScreenUpdating = True
Application.EnableEvents = True
End If
Next i
End If
Next cell
'Verzögerung hinzugefügt, um die CPU-Auslastung zu reduzieren
Application.Wait (Now + TimeValue("0:05:00"))
Loop
End Sub