Syntax error on function calls

dmqueen

Board Regular
Joined
Aug 5, 2014
Messages
53
Please help! I cannot get past these compiler errors on my function calls, and I can't figure out why. Neither function returns anything, so it should be straightforward.
I've marked the function calls receiving the errors with asterisks in the code comments and added the functions being called below that.
<code>
Sub fInput_Complete()
'Validate Entries
'copy listbox selections to worksheet
'go to next col
'col B
'verify entry was made
'go to next col

Dim NewRowNum As Integer
'Celllink 3 ROWS ABOVE for bound item where listboxes- on ALL sheets!!
'Start off in Column B
'Find the row just like in input begin: loop from the top until =, then one down
ActiveSheet.Range("A1").Select
'goto the top, and cycle down each line until you find the top of the entries, "="
'goto the top entry ready to insert the new entry
While ActiveCell.Value <> "="
ActiveCell.Offset(1, 0).Activate
Wend
'OK, we're on the new entry line
Dim EntryRowNum As Integer
Dim EntryColNum As Integer
Dim counter As Integer
counter = 0
EntryRowNum = Application.ActiveCell.Row
'Entry starts in Col B
'Start checking for empties!
'next function call copies Machines DropDown selection to worksheet
'Machine Drop dwns are in Col B!
'Compiler won't take function call
'syntax error
'/**********************************************************************************
fShowDDResult(EntryRowNum, 2)
'If no entry selected!
If Application.ActiveCell.Offset(0, 1).Value = "" Then
Call MsgBox("Please enter/select values in all columns and rerun when complete!", vbCritical, Application.Name)
End Sub
Else
'move on to col C
EntryColNum = 3
If ActiveCell.Value = Null Then
'If C is empty, ck for index above, indicating listbox
If ActiveCell.Offset(-3, 1) > 1 Then
'It's a listbox, copy the selected value into the worksheet
'Which listbox?
Application.ActiveCell(EntryRowNum & "C").Select.Value = ActiveSheet.ListBox1.Value
Dim CellLinkRow As Integer
CellLinkRow = EntryRowNum - 3
'another red line
'/***************************************************************************
fLinkedBoxValue(EntryRowNum, EntryRowCol)
Else:
'Ck for Notes field: only allowable blank
If Application.ActiveCell.Offset(-3, 1) = "Notes" Then End If
End If

End If
End If
'move onto Col D
EntryColNum = 4


End Sub
</code>
Functions being called:

<code>
Sub fShowDDResult(CurrRow, CurrCol)
Dim Row As Integer, Col As Integer
Col = CurrCol
Row = CurrRow
Dim dd As DropDown
Set dd = ActiveSheet.DropDowns(Application.Caller)
ActiveSheet.Cells(Row, Col).Value = dd.List(dd.Value)
End Sub


Function fLinkedBoxValue(aRange As Range)
Dim oneShape As Shape
Set aRange = aRange.Cells(1, 1)
For Each oneShape In aRange.Parent.Shapes
With oneShape
If .Type = msoFormControl Then
If .FormControlType = xlListBox Then
If .ControlFormat.LinkedCell = aRange.Address Then
LinkedBoxValue = .ControlFormat.List(.ControlFormat.ListIndex)
End If
End If
End If

End With
Next oneShape
End Function

</code>
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try removing the parenthesis.

fShowDDResult EntryRowNum, 2

fLinkedBoxValue EntryRowNum, EntryRowCol



Also, fLinkeBoxValue is not a function. Functions return a value to the caller. Its a sub procedure with arguments like fShowDDResult is written.
Code:
[COLOR=red]Sub[/COLOR] fLinkedBoxValue(aRange [COLOR=darkblue]As[/COLOR] Range)
    [COLOR=darkblue]Dim[/COLOR] oneShape [COLOR=darkblue]As[/COLOR] Shape
    [COLOR=darkblue]Set[/COLOR] aRange = aRange.Cells(1, 1)
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] oneShape [COLOR=darkblue]In[/COLOR] aRange.Parent.Shapes
        [COLOR=darkblue]With[/COLOR] oneShape
            [COLOR=darkblue]If[/COLOR] .Type = msoFormControl [COLOR=darkblue]Then[/COLOR]
                [COLOR=darkblue]If[/COLOR] .FormControlType = xlListBox [COLOR=darkblue]Then[/COLOR]
                    [COLOR=darkblue]If[/COLOR] .ControlFormat.LinkedCell = aRange.Address [COLOR=darkblue]Then[/COLOR]
                        LinkedBoxValue = .ControlFormat.List(.ControlFormat.ListIndex)
                    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
                [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
            [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]

        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
    [COLOR=darkblue]Next[/COLOR] oneShape
[COLOR=darkblue]End[/COLOR] [COLOR=red]Sub[/COLOR]

You would call a function with syntax like this.
x = MyFunction(arg1, arg2)
 
Last edited:
Upvote 0
Hello

It should be:

Code:
fShowDDResult EntryRowNum, 2

for the first line in red. It is a procedure, not a function.

For the other line in red, the function, you make a mistake when you don't assign an outcome value.
The function is called fLinkedBoxValue and you use LinkedBoxValue without the f in setting the result.

Also, when calling that function, it should be for example:

Code:
v = fLinkedBoxValue(EntryRowNum, EntryRowCol)

and v contains the result of the function.
 
Upvote 0
I still don't quite understand, the function flinkedBoxValue doesn't return anything. It has no return in it's signature nor a return line at the bottom of the function. ?
But I know I need t work on the diffs between subs and functions!
 
Upvote 0
I still don't quite understand, the function flinkedBoxValue doesn't return anything. It has no return in it's signature nor a return line at the bottom of the function. ?
But I know I need t work on the diffs between subs and functions!

Sure you need to work on that difference.

For example, change this:

Code:
[COLOR=#333333]LinkedBoxValue = .ControlFormat.List(.ControlFormat.ListIndex)[/COLOR]

to:

Code:
f[COLOR=#333333]LinkedBoxValue = .ControlFormat.List(.ControlFormat.ListIndex)[/COLOR]

See the first letter.

Do you understand it better now?

Can you please use
Code:
 tags in your post? It's only selecting the code that you paste, and clicking the # icon. Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,896
Members
449,194
Latest member
JayEggleton

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