I have created a function to receive three parameters.:
- An array of strings
- A worksheet name
- An index for the array of strings
When I compile I am getting a compile error stating:
Compile Error:
Expected:=
My call is:
Sub C_Button_ImportBOM_Click()
Dim strFilePathName As String
Dim strFileLine As String
Dim v As Variant
Dim RowIndex As Long
Dim mySheet As Worksheet
ActiveSheet.Name = "Import"
mySheet = Worksheets("Import")
strFilePathName = ImportFilePicker
v = QuickRead(strFilePathName)
For RowIndex = 0 To UBound(v)
PopulateNewLine (v(RowIndex), mySheet, RowIndex)
Next
End Sub
The function declaration is:
Function PopulateNewLine(SourceString As String, ImportSheet As Worksheet, CurrentRow As Long)
I have tried many things to no avail. Initially with just the first argument declared and used this worked okay.
Any ideas greatly appreciated.
Excel 2010 VBA
You are calling your function like a subroutine, i.e., you’re not returning a value from it and assigning it to a variable, as you’d normally do with a function. That means you need to call it without the parentheses surrounding the arguments:
If you really aren’t returning anything from it, you should probably turn it into a Sub for clarity’s sake:
On another note, you should qualify your mySheet reference, and as I mentioned in the comments, use
Set. It should look something like:Substitute whatever workbook Import is in for
ActiveWorkbookabove.