Hi guys,
Is it possible to refer to an object which is in another subroutine?
Or should i have to give its definition in each sub i need it?
Hi guys,
Is it possible to refer to an object which is in another subroutine?
Or should i have to give its definition in each sub i need it?
Last edited by navwelch; 04-03-2014 at 05:15 AM.
you can pass the object as an argument from one routine to the other or you can declare the variable outside both procedures-either as Private if both routines are in the same module or as Public if they're not
Josie
if at first you don't succeed try doing it the way your wife told you to
i am sorry, but i didnt fully get what you were saying. I am starting to learn the technical names so please do excuse my questions:
so i declared the variable as:
Private monthdatadate As Range
monthdatadate = Sheets("report").Range(Cells(2, 1), Cells(2, 4 + 2))
then when i tested a sub it says invalid outside procedure
you can only put the declaration outside the procedures
the assignment has to be within a procedure and you've gotta use Set because it's an object variable (and properly qualify the cells properties)Please Login or Register to view this content.
Please Login or Register to view this content.
oh i get it,
thanks a lot Joseph!
the test sub runs only wen the original sub has already been run. so i must create a new sub only for declarations. then ensure that it is run whenever i open the excel file so that any sub can be run without the need to run the original sub. i tried to save the declarations sub in Private Sub Workbook_Open(). but it wont work, do you have any solution?
normal module
thisworkbook modulePlease Login or Register to view this content.
or create a public function that returns this rangePlease Login or Register to view this content.
ok! 'public' has to be used since it goes outside the module, i get it now! phew!
thanks a lot!!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks