I'm trying to adapt a VBA code that uses the COM function getAllTradedVolume. I have use the above code in excel when i have a tab opened with one market and it works fine. I wanted to adapt it to a Coupon View Tab where there are lots of markets in the same spreadsheet. I can see that the code loops from Cell.(5,1) until it gets to a empty cell (Loop Until selecName = ""). I have tried to put something like: Loop Until selecName = "Stop" and put in Cell.(300,1) the word Stop so it stops there but i still just shows for the first market. Can some Guru help me out? My ultimate objective is just to have the weighted average odd next to every selection.
This is the code:
- Code: Select all
If ba Is Nothing Then
Set ba = New BettingAssistantCom.ComClass
End If
Dim tradedVol As Variant, tradedVols As Variant
Dim totalTraded As Double, totalProfit As Double
tradedVol = ba.getAllTradedVolume
If Not IsEmpty(tradedVol) Then
Dim i As Integer, r As Integer, selecName As String, j As Integer
r = 5
Do
selecName = Cells(r, 1).Value
If selecName <> "" Then
For i = 0 To UBound(tradedVol)
If tradedVol(i).Selection = selecName Then
Cells(r, 28).Value = tradedVol(i).actualBsp
Cells(r, 29).Value = tradedVol(i).totalBspBackMatchedAmount
Cells(r, 30).Value = tradedVol(i).totalBspLiabilityMatchedAmount
tradedVols = tradedVol(i).tradedVolumes
totalTraded = 0
totalProfit = 0
For j = 0 To UBound(tradedVols)
If tradedVols(j).totalMatchedAmount <> 0 Then
totalTraded = totalTraded + tradedVols(j).totalMatchedAmount
totalProfit = totalProfit + (tradedVols(j).odds - 1) * tradedVols(j).totalMatchedAmount
End If
If tradedVols(j).odds = Cells(r, 15).Value Then
Cells(r, 27).Value = tradedVols(j).totalMatchedAmount
End If
Next
Cells(r, 31).Value = Round((totalProfit / totalTraded) + 1, 2)
Exit For
End If
Next
End If
r = r + 1
Loop Until selecName = ""
End If
Application.EnableEvents = True