![]() |
Simple VBA question
Hi,
I have Macro1 and Macro2. Macro2 repeatedly calls Macro1, and after each execution attempts to draw some values from several variables in Macro1. Of course, it fails because I don't know how to declare those variables in Macro1 so they can be used by Macro2... I've read the help and tried declaring them with Public statement, but it doesn't work, cause apparently I'm doing it at a wrong level. I'm quite new to the concept of VBA, so this whole levels, modules & whatnot thing is totally lost upon me... :) Could somebody try to explain it to me how and where to declare those global variables so I can use them in both subs (macros). thanks in advance |
Simple VBA question
Srdan,
Declare the variables outside of and before any procedure. E.g., Public X As Integer Sub Macro1() ' code End Sub Sub Macro2() ' code End Sub -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Srdan Kovacevic" wrote in message ... Hi, I have Macro1 and Macro2. Macro2 repeatedly calls Macro1, and after each execution attempts to draw some values from several variables in Macro1. Of course, it fails because I don't know how to declare those variables in Macro1 so they can be used by Macro2... I've read the help and tried declaring them with Public statement, but it doesn't work, cause apparently I'm doing it at a wrong level. I'm quite new to the concept of VBA, so this whole levels, modules & whatnot thing is totally lost upon me... :) Could somebody try to explain it to me how and where to declare those global variables so I can use them in both subs (macros). thanks in advance |
Simple VBA question
Caution: Make sure that the variable is declared only once in your project.
And that it is also not declared inside of any of the modules. Found duplicating Public variables in my modules caused Crashes... -- sb "Chip Pearson" wrote in message ... Srdan, Declare the variables outside of and before any procedure. E.g., Public X As Integer Sub Macro1() ' code End Sub Sub Macro2() ' code End Sub -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Srdan Kovacevic" wrote in message ... Hi, I have Macro1 and Macro2. Macro2 repeatedly calls Macro1, and after each execution attempts to draw some values from several variables in Macro1. Of course, it fails because I don't know how to declare those variables in Macro1 so they can be used by Macro2... I've read the help and tried declaring them with Public statement, but it doesn't work, cause apparently I'm doing it at a wrong level. I'm quite new to the concept of VBA, so this whole levels, modules & whatnot thing is totally lost upon me... :) Could somebody try to explain it to me how and where to declare those global variables so I can use them in both subs (macros). thanks in advance |
All times are GMT +1. The time now is 01:27 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com