Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default variable not recognised in embedded macro

I have a main macro in whcih there is a variable "symbol"
"symbol" is derived from an inputbox
during the step by step running of the main macro if I type in the
immediate window
?symbol
it gives correct answer
there is another macro embeeded in the main macro at the end (before end
sub)
After the last codestatement of main macro the macro moves to the second
macro. once the step runs into the second macro if I type in the immdediate
window
?symbol
it gives blank
that means when the cursor moves into the second macro the variable "symbol"
is not recognised.
where do I do the mistake.

I hope I have made myself clear.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default variable not recognised in embedded macro

It sounds like the variable is out of scope, so you could pass the variable
to the second macro as a parameter:

Sub MainMacro()
Dim symbol As String
Call SecondMacro(symbol)
End Sub

Sub SecondMacro(ByRef symbol As String)
Debug.Print symbol
End Sub

...................Or.................declare the variable at module level:

Dim m_symbol As String

Sub MainMacro()
Debug.Print symbol
Call SecondMacro()
End Sub

Sub SecondMacro()
Debug.Print symbol
End Sub

You can look up "Understanding Scope and Visibility" in the VBE help for
details.

Best regards

John

"R..VENKATARAMAN" wrote in message
...
I have a main macro in whcih there is a variable "symbol"
"symbol" is derived from an inputbox
during the step by step running of the main macro if I type in the
immediate window
?symbol
it gives correct answer
there is another macro embeeded in the main macro at the end (before end
sub)
After the last codestatement of main macro the macro moves to the second
macro. once the step runs into the second macro if I type in the
immdediate
window
?symbol
it gives blank
that means when the cursor moves into the second macro the variable
"symbol"
is not recognised.
where do I do the mistake.

I hope I have made myself clear.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default variable not recognised in embedded macro

thank you Mr. John. that is the mistake I am doing. I saw help under
"Understanding Scope and Visibility"
of course to obviate the mistake I parked symbol in one of the cells of the
spread sheet in the main macro
and used the cell.value (instead of "symbol") in the second macro.

yes the mistake is giving <dim within the main macro. I thought that as the
second macro is called in the main macro, the main macro including calling
the second macro will be one procedure. It is not . The above help is
clear. thank you for pointing out this.Though I am fairly familiar with vba,
every day I learn a new thing.

thanks once again.;

"John" wrote in message
...
It sounds like the variable is out of scope, so you could pass the
variable to the second macro as a parameter:

Sub MainMacro()
Dim symbol As String
Call SecondMacro(symbol)
End Sub

Sub SecondMacro(ByRef symbol As String)
Debug.Print symbol
End Sub

..................Or.................declare the variable at module level:

Dim m_symbol As String

Sub MainMacro()
Debug.Print symbol
Call SecondMacro()
End Sub

Sub SecondMacro()
Debug.Print symbol
End Sub

You can look up "Understanding Scope and Visibility" in the VBE help for
details.

Best regards

John

"R..VENKATARAMAN" wrote in message
...
I have a main macro in whcih there is a variable "symbol"
"symbol" is derived from an inputbox
during the step by step running of the main macro if I type in the
immediate window
?symbol
it gives correct answer
there is another macro embeeded in the main macro at the end (before end
sub)
After the last codestatement of main macro the macro moves to the second
macro. once the step runs into the second macro if I type in the
immdediate
window
?symbol
it gives blank
that means when the cursor moves into the second macro the variable
"symbol"
is not recognised.
where do I do the mistake.

I hope I have made myself clear.








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default variable not recognised in embedded macro

No, unfortunately, you have not made yourself clear. It is not possible
to have one sub inside another. So, if your code is working, it is not
organized that way.

Maybe, you should share the actual code you are using. Copy & paste it
from the VBE to whatever program you use to post to the newsgroup.


--
Regards,

Tushar Mehta
www.tushar-mehta.com
Multi-disciplinary business expertise
+ Technology skills
= Optimal solution to your business problem
Recipient Microsoft MVP award 2000-2005

In article , venkat1926
@touchtelindia.net says...
I have a main macro in whcih there is a variable "symbol"
"symbol" is derived from an inputbox
during the step by step running of the main macro if I type in the
immediate window
?symbol
it gives correct answer
there is another macro embeeded in the main macro at the end (before end
sub)
After the last codestatement of main macro the macro moves to the second
macro. once the step runs into the second macro if I type in the immdediate
window
?symbol
it gives blank
that means when the cursor moves into the second macro the variable "symbol"
is not recognised.
where do I do the mistake.

I hope I have made myself clear.






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default variable not recognised in embedded macro

to Mr. Mehta
thank you.

probably it is my mistake that I did not make myself clear. "embedded" is
wrong word. I am calling another macro in the main macro
I am giving a trivial example

Public Sub test()
Dim symbol
symbol = InputBox("type the symbol")
testone
End Sub

Public Sub testone()
MsgBox symbol
End Sub

msgbox is blank

what mistake am I doing?


"Tushar Mehta" <tm_200310@tushar_hyphen_mehta_dot_see_oh_em wrote in
message om...
No, unfortunately, you have not made yourself clear. It is not possible
to have one sub inside another. So, if your code is working, it is not
organized that way.

Maybe, you should share the actual code you are using. Copy & paste it
from the VBE to whatever program you use to post to the newsgroup.


--
Regards,

Tushar Mehta
www.tushar-mehta.com
Multi-disciplinary business expertise
+ Technology skills
= Optimal solution to your business problem
Recipient Microsoft MVP award 2000-2005

In article , venkat1926
@touchtelindia.net says...
I have a main macro in whcih there is a variable "symbol"
"symbol" is derived from an inputbox
during the step by step running of the main macro if I type in the
immediate window
?symbol
it gives correct answer
there is another macro embeeded in the main macro at the end (before end
sub)
After the last codestatement of main macro the macro moves to the second
macro. once the step runs into the second macro if I type in the
immdediate
window
?symbol
it gives blank
that means when the cursor moves into the second macro the variable
"symbol"
is not recognised.
where do I do the mistake.

I hope I have made myself clear.






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
My first macro - doesnt work - function not recognised James Cornthwaite Excel Worksheet Functions 2 May 14th 06 05:13 PM
Create an external reference link with embedded variable Greentree Excel Worksheet Functions 1 October 9th 05 07:46 PM
Variable Chart Width (Embedded) Joel Mills Excel Programming 1 November 10th 04 06:29 PM
Can a variable workbook be embedded into an Excel funtion? Tom Ogilvy Excel Programming 1 August 11th 03 08:38 PM
Can a variable workbook be embedded into an Excel funtion? steve Excel Programming 0 August 11th 03 07:52 PM


All times are GMT +1. The time now is 11:15 AM.

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

About Us

"It's about Microsoft Excel"