Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Correct Syntax for Calling other Subs

Hi All,

What do I need to change in order to get the following to work. Should I be
using a function for this sort of routine?

I get the error "expected function or variable"

Sub TestSub(var1 As Integer)

TestSub = var1 + 2

End Sub

Sub testsub2()
Dim var1

var1 = TestSub(2)
MsgBox var1

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Correct Syntax for Calling other Subs

When your code returns a value it needs to be a Function, not a Sub:
Function TestSub(var1 As Integer) as Integer

TestSub = var1 + 2

End Function

Sub testsub2()
Dim var1

var1 = TestSub(2)
MsgBox var1

End Sub

"Andibevan" wrote:

Hi All,

What do I need to change in order to get the following to work. Should I be
using a function for this sort of routine?

I get the error "expected function or variable"

Sub TestSub(var1 As Integer)

TestSub = var1 + 2

End Sub

Sub testsub2()
Dim var1

var1 = TestSub(2)
MsgBox var1

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Correct Syntax for Calling other Subs

Thanks - didn't realise that

"K Dales" wrote in message
...
When your code returns a value it needs to be a Function, not a Sub:
Function TestSub(var1 As Integer) as Integer

TestSub = var1 + 2

End Function

Sub testsub2()
Dim var1

var1 = TestSub(2)
MsgBox var1

End Sub

"Andibevan" wrote:

Hi All,

What do I need to change in order to get the following to work. Should I

be
using a function for this sort of routine?

I get the error "expected function or variable"

Sub TestSub(var1 As Integer)

TestSub = var1 + 2

End Sub

Sub testsub2()
Dim var1

var1 = TestSub(2)
MsgBox var1

End Sub





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling subs from different workbooks R.VENKATARAMAN Excel Programming 0 September 26th 04 03:11 PM
Calling VBA add-in functions/subs from another Excel file. Bret Holle Excel Programming 1 September 17th 04 01:43 AM
calling subs Mike Excel Programming 4 April 8th 04 08:22 PM
calling subs, Doesn't seem to run fisrt time? CAA[_21_] Excel Programming 2 April 1st 04 08:23 PM
calling private subs dunlklee Excel Programming 1 December 16th 03 08:40 AM


All times are GMT +1. The time now is 03:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"