Calling a sub from another sub - passing variables

vbacoder

Active Member
Joined
Jul 7, 2007
Messages
354
Hi everyone,

I am having problems with the syntax involved in calling one subroutine from within another. I want to pass two variables calculated in a 'main' sub into the parentheses of another I am calling (see pseudocode below). When I pass one variable, everything works fine, however, when I try to include another, I get an error message - something about expecting an "=" in the syntax, which is clearly not correct.

Sub main()

row = .....

column = .....

counting(row, column)

End sub()


Sub counting (row, column)

.....


End sub

Many thanks,

vcoder
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,357
Office Version
  1. 365
Platform
  1. Windows
Drop the ().

And don't use things like row/column for variable names.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Alternative syntax

Call counting(Myrow, Mycolumn)
 

vbacoder

Active Member
Joined
Jul 7, 2007
Messages
354
Hi guys,

Thanks for your replies.

Norie - rows & columns were just an e.g. off the top of my mind. I have other data and variable names in the real sheet. So would counting row, column work?

VoG II - This looks like a FTN trick ;) Thanks, I'll try it!

Many thanks for your help again!

vcoder
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,357
Office Version
  1. 365
Platform
  1. Windows
vcoder

Not sure what you mean by this.:eek:
So would counting row, column work?
 

vbacoder

Active Member
Joined
Jul 7, 2007
Messages
354
You said drop the (), so I thought you were referring to the calling syntax
 

vbacoder

Active Member
Joined
Jul 7, 2007
Messages
354
I get an error with this line:

counting(row, column)
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,357
Office Version
  1. 365
Platform
  1. Windows
Ah, right get what you mean now.:oops:

Yes this should work.
Code:
counting row, column
PS When posting code it's normally better to post the actual code.:)
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
I always use the Call mysub(x,y,...) syntax and - yes - I was brought up on Fortran in the last century.
 

vbacoder

Active Member
Joined
Jul 7, 2007
Messages
354
Yes this should work.
Code:
counting row, column
PS When posting code it's normally better to post the actual code.:)

Thanks Norie!

vcoder
 

Forum statistics

Threads
1,181,056
Messages
5,927,864
Members
436,573
Latest member
CMR237

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
Top