Macro doesn't work in Excel 2003

P

Polly

I write a macro in Excel 2002. When I try to run the
macro in Excel 2003, it doesn't work. Excel prompted that
I have not defined "Sub" or "Function" . However, the
function i used is "Mid" which is a function of macro. I
don't understand why. Please help me!
 
G

Guest

My codes are as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Add_Click()
flag = 0
new_item = ItemName.Value
With ActiveSheet.PivotTables(1)
For j = 1 To .PivotFields("[Item].
[Itemcname]").PivotItems.Count
searchchar = "(09"
mypos = InStr(4, .PivotFields("[Item].
[Itemcname]").PivotItems(j).Name, searchchar, 1)
num1 = Len(.PivotFields("[Item].
[Itemcname]").PivotItems(j).Name)

If new_item = Mid(.PivotFields("[Item].
[Itemcname]").PivotItems(j).Name, mypos + 1, 10) Then
new_item = Right(.PivotFields("[Item].
[Itemcname]").PivotItems(j).Name, num1 - mypos + 2)
flag = 1
GoTo canfind
End If
Next
If flag = 0 Then
MsgBox "Cannot Find This Item"
GoTo Xfind
End If
End With

canfind:
ListBox1.AddItem (new_item)
ItemName.Value = ""

Xfind:
ItemName.Value = ""
End Sub

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It prompted that I have defined"Sub" or "Function".
However, this program doesn't involve any user-defined
function.
 
S

Simon Murphy

Polly
in vba editor click tools>>references and uncheck any that
say missing. This 'not defined' error is often to do with
lost or broken references

cheers
Simon
 
Top