Bonjour,
J'ai fait une petite macro qui doit m'avertir à chaque fois qu'une valeur descend en-dessous d'un certain seuil ou monte au-dessus d'un autre seuil.
Mais elle bug en me disant : erreur 9 : l'indice n'appartient pas à la sélection sur la ligne en gras ci-dessous.
Quelqu'un peut m'aider ?
L'excel sur ci-joint : Cijoint.fr - Service gratuit de dépôt de fichiers
Sub MonitoringQuotes()
Dim ValuesNameRange As Range, _
RTimeQuotesRange As Range, _
RTimeQuotesAlertRange As Range, _
QuotesLinesRange As Range
Dim TabNames As Variant, _
TabQuotes As Variant, _
TabQuotesAlert As Variant, _
RTValue As Variant, _
RTAlertTop As Variant, _
RTAlertStop As Variant
Dim RTAlertStopbis As Variant
Dim AlertSound As Integer
Dim AlertValues As String
Dim NbLines As Long, _
i As Long
Set ValuesNameRange = ThisWorkbook.Worksheets(portfolioSheet).Range(ValuesName)
Set RTimeQuotesRange = ThisWorkbook.Worksheets(portfolioSheet).Range(RTimeQuotes)
Set RTimeQuotesAlertRange = ThisWorkbook.Worksheets(portfolioSheet).Range(RTimeQuotesAlert)
TabNames = ValuesNameRange.Value
TabQuotes = RTimeQuotesRange.Value
TabQuotesAlert = RTimeQuotesAlertRange.Value
NbLines = UBound(TabQuotes, 1)
AlertSound = 0
AlertValues = ""
For i = 1 To NbLines
RTValue = TabQuotes(i, 1)
If IsEmpty(RTValue) Or Not IsNumeric(RTValue) Then Exit For
RTAlertTop = TabQuotesAlert(i, 1)
RTAlertStop = TabQuotesAlert(i, 2)
RTAlertStopbis = TabQuotesAlert(i, 3)
If Not IsEmpty(RTAlertTop) And IsNumeric(RTAlertStop) And RTValue < RTAlertStop Then
If AlertSound = 0 Then
AlertValues = TabNames(i, 1) & " (" & RTValue & " < " & RTAlertStop & ")"
Else
AlertValues = AlertValues & " *** " & TabNames(i, 1) & " (" & RTValue & " < " & RTAlertStop & ")"
End If
AlertSound = 1
End If
If Not IsEmpty(RTAlertTop) And IsNumeric(RTAlertStopbis) And RTValue > RTAlertStopbis Then
If AlertSound = 0 Then
AlertValues = TabNames(i, 1) & " (" & RTValue & " > " & RTAlertStopbis & ")"
Else
AlertValues = AlertValues & " *** " & TabNames(i, 1) & " (" & RTValue & " > " & RTAlertStopbis & ")"
End If
AlertSound = 1
End If
Next
Call MonitoringQuotesColor(3)
If AlertSound Then
Application.StatusBar = "ALERTES !!! : " & AlertValues
If Sheets(portfolioSheet).EnabledSound.Value Then Call PlaySound
If Sheets(portfolioSheet).EnabledMail.Value Then
Set QuotesLinesRange = ThisWorkbook.Worksheets(portfolioSheet).Range("QuotesLines")
Call Envoi_Email_Msg("ALERTES !!! : " & AlertValues, QuotesLinesRange)
End If
End If
End Sub
J'ai fait une petite macro qui doit m'avertir à chaque fois qu'une valeur descend en-dessous d'un certain seuil ou monte au-dessus d'un autre seuil.
Mais elle bug en me disant : erreur 9 : l'indice n'appartient pas à la sélection sur la ligne en gras ci-dessous.
Quelqu'un peut m'aider ?
L'excel sur ci-joint : Cijoint.fr - Service gratuit de dépôt de fichiers
Sub MonitoringQuotes()
Dim ValuesNameRange As Range, _
RTimeQuotesRange As Range, _
RTimeQuotesAlertRange As Range, _
QuotesLinesRange As Range
Dim TabNames As Variant, _
TabQuotes As Variant, _
TabQuotesAlert As Variant, _
RTValue As Variant, _
RTAlertTop As Variant, _
RTAlertStop As Variant
Dim RTAlertStopbis As Variant
Dim AlertSound As Integer
Dim AlertValues As String
Dim NbLines As Long, _
i As Long
Set ValuesNameRange = ThisWorkbook.Worksheets(portfolioSheet).Range(ValuesName)
Set RTimeQuotesRange = ThisWorkbook.Worksheets(portfolioSheet).Range(RTimeQuotes)
Set RTimeQuotesAlertRange = ThisWorkbook.Worksheets(portfolioSheet).Range(RTimeQuotesAlert)
TabNames = ValuesNameRange.Value
TabQuotes = RTimeQuotesRange.Value
TabQuotesAlert = RTimeQuotesAlertRange.Value
NbLines = UBound(TabQuotes, 1)
AlertSound = 0
AlertValues = ""
For i = 1 To NbLines
RTValue = TabQuotes(i, 1)
If IsEmpty(RTValue) Or Not IsNumeric(RTValue) Then Exit For
RTAlertTop = TabQuotesAlert(i, 1)
RTAlertStop = TabQuotesAlert(i, 2)
RTAlertStopbis = TabQuotesAlert(i, 3)
If Not IsEmpty(RTAlertTop) And IsNumeric(RTAlertStop) And RTValue < RTAlertStop Then
If AlertSound = 0 Then
AlertValues = TabNames(i, 1) & " (" & RTValue & " < " & RTAlertStop & ")"
Else
AlertValues = AlertValues & " *** " & TabNames(i, 1) & " (" & RTValue & " < " & RTAlertStop & ")"
End If
AlertSound = 1
End If
If Not IsEmpty(RTAlertTop) And IsNumeric(RTAlertStopbis) And RTValue > RTAlertStopbis Then
If AlertSound = 0 Then
AlertValues = TabNames(i, 1) & " (" & RTValue & " > " & RTAlertStopbis & ")"
Else
AlertValues = AlertValues & " *** " & TabNames(i, 1) & " (" & RTValue & " > " & RTAlertStopbis & ")"
End If
AlertSound = 1
End If
Next
Call MonitoringQuotesColor(3)
If AlertSound Then
Application.StatusBar = "ALERTES !!! : " & AlertValues
If Sheets(portfolioSheet).EnabledSound.Value Then Call PlaySound
If Sheets(portfolioSheet).EnabledMail.Value Then
Set QuotesLinesRange = ThisWorkbook.Worksheets(portfolioSheet).Range("QuotesLines")
Call Envoi_Email_Msg("ALERTES !!! : " & AlertValues, QuotesLinesRange)
End If
End If
End Sub
Dernière édition: