How to run the attached macro?

Hendrixx

New Member
Joined
Nov 14, 2017
Messages
17
Hi all,
I am a trader and very much a vba novice (so please use very small words!).

I have a spreadsheet from my broker, on which I have built a trading system.
Everything works very well, but approximately 10% of the time, the "order status" does not fill back into the spreadsheet and I use this "status" ("filled" etc) for subsequent actions on the orders.

I have found the following code in vba, but cannot (manually - I suspect it runs on a call from elsewhere) get it to run - it opens a dialogue box asking for a macro name (the same box that would open if I clicked the View-->Macros -->View Macros menu).

The macro itself is in the (I'm not sure of the exact terminology) worksheet module (VBAProject-->Microsoft Excel Objects-->Worksheet Name)

Code:
 ' update order status
Public Sub UpdateOrderStatus(id As Long, status As String, filled As Double, remaining As Double, avgFillPrice As Double, parentId As Long, lastFillPrice As Double)
    OrderUtils.UpdateOrderStatus orderStatusTable, id, status, filled, remaining, avgFillPrice, parentId, lastFillPrice
End Sub

There is also a module (under Modules) called OrderUtils, containing the following code:

Code:
' update order status
Public Sub UpdateOrderStatus(orderStatusTable As Range, orderId As Long, status As String, filled As Double, remaining As Double, avgFillPrice As Double, parentId As Long, lastFillPrice As Double)
    ' find row to update by using orderId
    Dim rowId As Long
    rowId = FindOrderRowIndex(orderId, orderStatusTable)
    If rowId = 0 Then Exit Sub
    
    If rowId <= orderStatusTable.Rows.count Then
        orderStatusTable(rowId, Col_ORDERSTATUS).value = status
        orderStatusTable(rowId, Col_FILLED).value = filled
        orderStatusTable(rowId, Col_REMAINING).value = remaining
        orderStatusTable(rowId, Col_AVGFILLPRICE).value = avgFillPrice
        orderStatusTable(rowId, Col_LASTFILLPRICE).value = lastFillPrice
        orderStatusTable(rowId, Col_PARENTID).value = parentId
    End If
End Sub

All variables (as far as I can tell) are properly declared at the beginning of each of the modules.

Is this enough information to answer the question:

Is there anything I can change, add, or rewrite, to enable this macro "UpdateOrderStatus" to be run manually?

Thanks

Phil
 
Last edited by a moderator:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
The reason subroutine in worksheet module does not run is that it has a list of parameters that are expected to have values to run it.
Code:
Public Sub UpdateOrderStatus([COLOR=#ff0000]id As Long, status As String, filled As Double, remaining As Double, avgFillPrice As Double, parentId As Long, lastFillPrice As Double[/COLOR])
    OrderUtils.UpdateOrderStatus orderStatusTable, id, status, filled, remaining, avgFillPrice, parentId, lastFillPrice
End Sub
The only procedure(s) that can work as entry point is the one which doesn't have any parameters in its definition. That means you need to either

1. change the signature of worksheet subroutine to remove all parameters and declare/initialize variables inside
Code:
Public Sub UpdateOrderStatus()
[COLOR=#0000ff]    Dim id As Long, status As String, filled As Double, remaining As Double, avgFillPrice As Double, parentId As Long, lastFillPrice As Double

[/COLOR][COLOR=#008000]    ' Assign values to variables[/COLOR][COLOR=#0000ff]
    Set orderStatusTable = Thisworkbook.Sheets("Sheet1").Range("a1:d50")
    id = 500
[/COLOR][COLOR=#008000]    ' etc[/COLOR][COLOR=#0000ff][/COLOR][COLOR=#FF0000]

[/COLOR]
    OrderUtils.UpdateOrderStatus orderStatusTable, id, status, filled, remaining, avgFillPrice, parentId, lastFillPrice
End Sub
2. create another subroutine without parameters that calls UpdateOrderStatus providing it with actual values in call.
Code:
Public Sub mainSub()
    UpdateOrderStatus 500, "OK", 5.1, 2.7, 44.31, 22, 41.12
End Sub

Also, both of these subroutines (in worksheet module and OrderUtils module) have same name; you might want to change that to avoid confusion.
 
Upvote 0
Thanks V_Malkoti,

I think I understand what you're saying.
However, I can't declare these variables as they are what I am trying to discover (status, fill price etc). The only one I do have is the id. It appears that I misunderstood the purpose of the macro. I thought it "went out and requested" those variables (status, fill price etc) from the broker (which is what I wanted), but it appears this is not the case.

Back to the drawing board....

I appreciate your reply. Thank you.
 
Upvote 0

Forum statistics

Threads
1,216,018
Messages
6,128,305
Members
449,439
Latest member
laurenwydo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top