+ Reply to Thread
Results 1 to 3 of 3

Accessing Dim from child sub

Hybrid View

  1. #1
    Registered User
    Join Date
    08-10-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    12

    Accessing Dim from child sub

    Hi All,

    I need to to use dates in different formats in many of my Sub.

    What i thought i could do is creat a sub as below and run the sub/function before i run my main sub.

    Sub DateVars()
    
    Dim ddmmyy
    
        ddmmyy = Format(Date, "ddmmyy")
    
    End Sub
    and then run the code from the main sub

    Sub DatePassTest()
    
    DateVars
    
    Cells(10, 4).Value = ddmmyy
    
    End Sub
    How can i get this to work?

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Accessing Dim from child sub

    Hello,

    if you want to access a variable in different procedures, you need to declare it at the top of the module as a public variable.

    Public ddmmyy
    
    Sub DateVars()
    
        ddmmyy = Format(Date, "ddmmyy")
    
    End Sub
    
    Sub DatePassTest()
    
         DateVars 
    
         Cells(10, 4).Value = ddmmyy
    
    End Sub

  3. #3
    Registered User
    Join Date
    08-10-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Accessing Dim from child sub

    Thank you, it worked.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1