Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

defining subroutine in the main program

  Asked By: Ludwig    Date: Jan 21    Category: MS Office    Views: 787
  

How do we define subroutine in the main program. When I run this code,
VBA says that subroutine taskfinder is not defined.

Sub Macro1()
m=4
n=6
taskfinder()
end sub

Public Sub taskfinder()
task = 1
For i = 1 To n
For j = 1 To m
TF(i) = TF(i) + 1
Next
iif(TF(i)<TF(task),task=i,task=task)
Next
End Sub

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Sophia Campbell     Answered On: Jan 21

try deleting the () from taskfinder().

Get back if it does/doesn't work.

 
Answer #2    Answered By: Andrew Brown     Answered On: Jan 21

..and shouldn't
iif(TF(i)<TF(task),task=i,task=task)
be
task = IIf(TF(i) < TF(task), i, task)

?

 
Answer #3    Answered By: Gustavo Costa     Answered On: Jan 21

If this is a Cut/Paste, there is a clue in that your

Sub Macro1()

ends with
end sub ' No big "E"

instead of with
End Sub ' Big "E"

The words "End Sub" should also be highlighted to indicate they are
recognized.

Also, a Call has no () unless passing variables:

The line
taskfinder()
should be
taskfinder
or
Call taskfinder


If you put the word "Call" in there, it will be highlighted to
indicate it is recognized as you enter it.

 
Answer #4    Answered By: Tommy Thompson     Answered On: Jan 21

Cld you answer me few questions from your code?

Sub Macro1()
m=4
n=6
taskfinder() // Simply replace it with Call taskfinder.
end sub

Public Sub taskfinder()
task = 1
For i = 1 To n
For j = 1 To m
TF(i) = TF(i) + 1 //Is TF an array?
If it is then it wld work, you just need to declare one global array as TF.
Next
iif(TF(i)<TF(task),task=i,task=task)
Next
End Sub

 
Didn't find what you were looking for? Find more on defining subroutine in the main program Or get search suggestion and latest updates.




Tagged: