Why Syntax Error, cant find why?

ilcaa

Well-known Member
Joined
May 25, 2005
Messages
751
Office Version
  1. 365
Platform
  1. Windows
I cant understand why it is is telling me Syntax Error, maybe i just cant see it...The syntax error occurs at Process_Trades(Trade, TradeNumber) bolded below...

Code:
Sub Get_Trades(TradeFile)

Dim Trade As String
Dim TradeNumber As Integer

TradeNumber = 1

'Get 1 Trade from trade file
        Trade = Mid(TradeFile, CharCount, 2000)
              
'Process trades
        If Left(Trade, 1) = "A" Or Left(Trade, 1) = "P" Then
            [B]Process_Trades(Trade, TradeNumber)[/B] 
           TradeNumber = TradeNumber + 1
        End If

-----------------------------------------------------------
Sub Process_Trades(Trade As String, TradeNumber As Integer)

Range("a7").Value = "Trades"
Set TradeRow = Range("a65000").End(xlUp).Offset(1, 0)
           
           'Add Trade Data to Column A, Format as Text
                TradeRow.Value = Trade
                TradeRow.NumberFormat = "@"
                    
            'Add Trade Number to Column B
                If Len(TradeRow.Value) > 1 Then
                    TradeRow.Offset(0, 1).Value = TradeNumber
                End If
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
It might help if you indicate which line is highlighted when you get the error.
 
Upvote 0
It might help if you indicate which line is highlighted when you get the error.

so sorry, i just edited the original Post in Bold, its Process_Trades(Trade, TradeNumber)
 
Upvote 0
I'm honestly not sure WHY it's a syntax error.
But here's a couple different ways to write it that do work

Call Process_Trades(Trade, TradeNumber)

or

Process_Trades Trade, TradeNumber
 
Upvote 0
I'm honestly not sure WHY it's a syntax error.
But here's a couple different ways to write it that do work

Call Process_Trades(Trade, TradeNumber)

or

Process_Trades Trade, TradeNumber


Added Call, it works

thank you!
 
Upvote 0
Parentheses are only required if you are:
1. Using the return value from a function; or
2. Using the Call statement; or
3. Explicitly trying to evaluate or de-reference an argument you are passing.
 
Upvote 0
Thanks Rory, that's almost cleared it up.

But in the below code, why does test2 work, but test3 does not ?

Rich (BB code):
Sub test()
test2 ("Hello") 'This works
test3 ("Hello", "There") 'This does not
End Sub

Sub test2(MyString)
MsgBox MyString
End Sub

Sub test3(MyString1, MyString2)
MsgBox MyString1 & " " & MyString2
End Sub
 
Upvote 0
Calling test2 evaluates "hello", which is just "hello", and passes that to test2.
Calling test3 tries to evaluate "hello", "there" which doesn't make any sense so it fails. Even if it did evaluate to something, you would only be passing one argument, rather than the required two. You could use:
Code:
test3 ("hello"), ("there")
but its a little unnecessary. ;)
 
Upvote 0
Hmm, thanks.
I still don't really understand it.

I'll chalk it up as one of those things I know because "that's just the way it is", without really understanding why.
I have quite a few of those...;)
 
Upvote 0

Forum statistics

Threads
1,214,665
Messages
6,120,803
Members
448,990
Latest member
rohitsomani

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