Closed Thread
Results 1 to 6 of 6

Referencing dates in VBA code

  1. #1
    Registered User
    Join Date
    01-15-2009
    Location
    Idaho Falls
    MS-Off Ver
    Excel 2003
    Posts
    3

    Referencing dates in VBA code

    This is my first post and I'm new to VBA so please bear with me. My code takes several different month-end reports and formats and compiles them into one. It also pulls up last month's completed report and copies over certain tables and formatting to the new report.

    Within all of these different reports, the month end dates are referenced extensively in different ways. For example 12-31-08 shows up several different times in worksheets, in file names, and in worksheet names through the code. It also references the previous month end date (11-30-08) in similar ways as well.

    I've been hoping that I could just create variables like "curmonth" and "lastmonth" to reference these dates throughout the code, but after searching extensively online and in a book or two, I haven't found the best solution. I probably don't know the precise way to phrase my question.

    For now I'm just doing Find and replace for each new month-end report.

    Is there an easy answer?

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    You can define variables to contain the dates:
    Please Login or Register  to view this content.
    Beyond that, I don't understand your question.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    01-15-2009
    Location
    Idaho Falls
    MS-Off Ver
    Excel 2003
    Posts
    3
    Sorry for the vague question.

    Now is there some special punctuation I would need to include to reference curDTE in the following ways:

    Workbooks.Open Filename:= "C:\MY DOCUMENTS\Unbilled and BIE\12-31-08\File4000.dbf"

    Sheets("Sheet5").Name = "GL 12-31-08 Balance"

    Sheets("GL 12-31-08 Balance").Select

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Please take a few minutes to read the Forum Rules, and then edit your post to wrap your code with Code Tags.

  5. #5
    Registered User
    Join Date
    01-15-2009
    Location
    Idaho Falls
    MS-Off Ver
    Excel 2003
    Posts
    3
    Thanks. Will do.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Thread closed.

Closed 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