"Compile error: sub or function not defined"

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

Hi,

I defined five variables a, b, c. d and argmin (all variant), and then
when I try to use

argmin = min(a,b,c,d),

the compiler says:

"compile error: sub or function not defined"

Do I have to do any special declarations to use the min function?

Please help.

Thanks a lot,

Joe.
 
To provide more context for the above problem, what I was trying to do
was to look at the first four characters in column entries (starting
from I2) for part numbers. (If all four characters are alphabets, the
part number is not valid and the corresponding row entry has to be
deleted). So I tried to use the following macro (modified from another
macro that runs fine):

Sub trimNonlegit()

Dim R As Range
Dim NonLegit As Range
Dim argmin As Variant
Dim a As Variant
Dim b As Variant
Dim c As Variant
Dim d As Variant

Application.ScreenUpdating = False

Set R = Worksheets("Demand").Range("I2")

Do While Not IsEmpty(R)
a = Asc(Mid(R, 1, 1))
b = Asc(Mid(R, 1, 2))
c = Asc(Mid(R, 1, 3))
d = Asc(Mid(R, 1, 4))
argmin = Min(a, b, c, d)
If argmin > 57 Then
If NonLegit Is Nothing Then
Set NonLegit = R
Else
Set NonLegit = Union(R, NonLegit)
End If
End If
Set R = R.Offset(1, 0)
Loop

If NonLegit Is Nothing Then
'do nothing
Else
NonLegit.EntireRow.Delete
End If

End Sub
 
Hello Joe,

To use an Excel worksheet function in VBA you have use the followin
method...

argmin = Application.WorksheetFunction.Min(a, b, c, d)

Sincerely,
Leith Ros
 
Back
Top