'Expected Sub, Function, or Property' Error Calling A Function

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,632
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
What would be a likely cause of an "Expected Sub, Function, or Property" error with the highlighted line in the code snippet below. Anyone able to help me with a solution?

Rich (BB code):
...
Do While .Cells(tcr, 27) <> ""
     ttle = .Range("C" & i)
     tmdl = .Range("AA" & tcr)
     fndrow ttle, tmdl
     MsgBox tmdl & " found at row: " & fndrow, , ttle
Loop
...

And then I have this function ...
VBA Code:
Function fndrow(ttle As String, tmdl As String) As Long
    Dim rng As Range
    Dim rowNumber As Long
    Dim found As Boolean
  
    ' Define the range to search
    Set rng = ws_ifm.Range("A3:A" & ws_ifm.Cells(ws.Rows.count, "C").End(xlUp).Row)
  
    ' Initialize variables
    found = False
  
    ' Loop through each cell in column C
    For Each cell In rng
        ' Check if Column C equals Value1 and Column F equals Value2 in the same row
        If cell.Value = tmdl And ws_ifm.Cells(cell.Row, "C").Value = ttle Then
            rowNumber = cell.Row
            found = True
            Exit For ' Exit loop once a match is found
        End If
    Next cell
End Function
 
You are using fndrow for 2 entirely different things.

Usage 1 - as a long variable
Rich (BB code):
    Dim f_rowcnt As Long, lstrow As Long, floop As Long, fndrow As Long, i As Long
    fndrow = -1
    fndrow = i

Usage 2 - as a Function
Rich (BB code):
myrow = fndrow(ttle, tmdl)
' Calling
Function fndrow(ttle As String, tmdl As String) As Long

You need to change the name of one of them. ie if you opt to change the first. Remove fndrow As Long and change the other 2 lines from fndrow to myrow.
 
Upvote 0
Solution

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Thank you Alex, you indeed found the culprit. I had totally forgotten that I had used fdrow already in another context. Changing my function name seems to have solved the problem. Thank you all for helping me through this.
 
Upvote 0
What would be a likely cause of an "Expected Sub, Function, or Property" error with the highlighted line in the code snippet below. Anyone able to help me with a solution?

To avoid a loop you could do this.

VBA Code:
Public Sub subFindRow()
Dim lngRow As Long
Dim ttle As String
Dim tmdl As String
Dim arr() As Variant
Dim ws_ifm As Worksheet

    Set ws_ifm = Sheets("Sheet2")
  
    ttle = "a"
  
    tmdl = "b"
  
    arr = Evaluate("LET(a," & ws_ifm.Name & "!" & ws_ifm.Range("S3:T" & ws_ifm.Cells(Rows.Count, "T").End(xlUp).Row).Address & ",TAKE(FILTER(ROW(a)," & _
      "(INDEX(a,,1)=" & """" & ttle & """" & ")*(INDEX(a,,2)=" & """" & tmdl & """" & "),0),1))")
  
    lngRow = arr(1)
  
    MsgBox tmdl & " found at row : " & lngRow, , ttle

End Sub

Expected Sub Function.xlsm
ST
2ST
3ab
4hi
5ka
6mr
7ly
8zp
9ai
10xh
11ou
12wl
13kr
Sheet2
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,225,195
Messages
6,183,482
Members
453,162
Latest member
Coldone

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