Programmazione Excel Macro per Excel Trading System (1 Viewer)

Ciao

Ho una piccola macro per il mio TS sviluppato con Excel ma non mi funziona con i dati DDE, funziona solo se inserisco i dati manualmente, oppure se una volta evidenziata la cella che ha verificato la condizione impostata clicco nella barra della formula e do l'invio.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Intersect(Target, Range("A2:A41")) Is Nothing Then Exit Sub
Application.EnableEvents = False
If UCase(Target) = "COMPRA" Or UCase(Target) = "VENDI" Then
Worksheets(2).Cells(Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row + 1, "A") = Cells(Target.Row, "A")
Worksheets(2).Cells(Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row, "C") = Cells(Target.Row, "C")
Worksheets(2).Cells(Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row, "E") = Cells(Target.Row, "E")
Worksheets(2).Cells(Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row, "G") = Cells(Target.Row, "AL")
If UCase(Target) = "COMPRA" Or UCase(Target) = "VENDI" Then
MsgBox Cells(Target.Row, "A") & " " & Cells(Target.Row, "C") & " " & Cells(Target.Row, "E")
End If
End If
Application.EnableEvents = True
End Sub


Ringrazio fin da ora chi vorrà darmi una mano a risolvere questo problema.
 

marofib

Forumer storico
usa l'evento calculate...... Private Sub Worksheet_Calculate()

change non sente il dde
 
Ultima modifica:

marofib

Forumer storico
devi gestire diversamente ...Target

metti direttamente la cella
ora io non ho dde attivi per provare a modificartela
cmq se cerchi in internet dde calculate...change vedrai quanto c'e' scritto
 

AndrewLR

Nuovo forumer
Application.Calculation = xlCalculationAutomatic

Magari aggiungi un bottone per accenderle e spegnerle collegato a questa:


Public Sub Switch_Calc_On_Off()

If Application.Calculation = xlCalculationAutomatic Then
Application.Calculation = xlCalculationManual
Else
Application.Calculation = xlCalculationAutomatic
End If

Sub
 
l'ho provata così ma ancora non funziona:

Private Sub Worksheet_Calculate()
On Error Resume Next
If Intersect(Target, Range("A2:A41")) Is Nothing Then Exit Sub
Application.Calculation = xlCalculationAutomatic
If UCase(Target) = "COMPRA" Or UCase(Target) = "VENDI" Then
Worksheets(2).Cells(Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row + 1, "A") = Cells(Target.Row, "A")
Worksheets(2).Cells(Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row, "C") = Cells(Target.Row, "C")
Worksheets(2).Cells(Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row, "E") = Cells(Target.Row, "E")
Worksheets(2).Cells(Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row, "G") = Cells(Target.Row, "AL")
If UCase(Target) = "COMPRA" Or UCase(Target) = "VENDI" Then
MsgBox Cells(Target.Row, "A") & " " & Cells(Target.Row, "C") & " " & Cells(Target.Row, "E")
End If
End If
Application.Calculation = xlCalculationAutomatic
End Sub
 

marofib

Forumer storico
facciamo cosi'
cmq usare calculate o change a me non piace perche' col dde c'e un sovraccarico e quindi diventa lento

fai una routine temporizzata...ogni tot secondi, minuti ecc vai a leggere le celle e fine della storia
 

marofib

Forumer storico
in giro ti proporranno il metodo OnTime

io preferisco gestirlo con un timer

in un modulo inserisci:

Private Declare Function SetTimer Lib "User32" _
(ByVal hWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

Private Declare Function KillTimer Lib "User32" _
(ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Dim TimerID As Long

Public Sub TimerOff()
KillTimer 0, TimerID
End Sub

Public Sub TimerOn(Interval As Long)
On Error Resume Next
TimerID = SetTimer(0, 0, Interval, AddressOf miaroutine)

End Sub




Private Sub miaroutine()
'blablabla bla
End Sub

'in un bottone attivi il timer con
TimerOn 1000 '(1 secondo)
'oppure lo spegni con

timerOff
 

Users who are viewing this thread

Alto