Consulting

Results 1 to 12 of 12

Thread: What is the code for the current date?

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    What is the code for the current date?

    I have a print routine that I want to add the current system date. Can anyone please tell me the code? Thanks
    Peace of mind is found in some of the strangest places.

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Date() or now().

  3. #3
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Or if you are printing the same worksheet and only some of the data is changing, you can put
    =Today()
    in the date cell and it will always be updated to the current system date.

  4. #4
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Sorry, =now() is OK but gives the time as well , but date() is Not OK and will give an error message.

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Use Format with Now() and you can present it as you wish.

    Format(Now(), "dd MMMM yyyy")
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Just use either of these two, no parenthasis ...

    Date 'Current system date
    Time 'Current system time
    Note that the Date method will not have a time value associated with it; in other words it will be a whole (serial) number.

  7. #7
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Hi Zack,


    I have some headings I want repeated at the top of every page. What is the best way to accomplish this?

    Public Sub PrintMtvGroupList()
    LastRow = Range("A65536").End(xlUp).Row
    Row = 3
    Range("C1:G1").Font.Bold = "True"
    Range("C1").Value = "Group Name"
    Range("D1").Value = "Bill Rep"
    Range("E1").Value = "Ext."
    Range("F1").Value = "Group #"
    Range("G1").Value = "Back Up"
    For i = 1 To LastRow Step 6
        Range("C" & Row).Value = Range("B" & i).Text
        Range("D" & Row).Value = Range("B" & i + 1).Text
        Range("E" & Row).Value = Range("B" & i + 2).Text
        Range("F" & Row).Value = Range("B" & i + 3).Text
        Range("G" & Row).Value = Range("B" & i + 4).Text
        Row = Row + 1
     If Row = 40 Then
        Call PrintHeadings
     End If
    Next i
    Columns("C:G").PrintPreview
    Columns("C:G").ClearContents
    End Sub
    Peace of mind is found in some of the strangest places.

  8. #8
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    With code? Set up a For Each ws In ActiveWorkbook.Worksheets loop.

    Manually? Select the left-most sheet, press/hold Shift, select the right-most sheet, make your change in any sheet, right click any sheet tab, select Ungroup.

    I prefer the manual way. You do it once, you're done. I'm lazy.

  9. #9
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Just have one sheet. Would prefer code
    Peace of mind is found in some of the strangest places.

  10. #10
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    I tried an approach where I was checking a counter I defined after each row was written but it never forced the routine to work....Here is my febile attempt..

    Public Sub PrintMtvGroupList()
    LastRow = Range("A65536").End(xlUp).Row
    Row = 3
    Range("C1:G1").Font.Bold = "True"
    Range("C1").Value = "Group Name"
    Range("D1").Value = "Bill Rep"
    Range("E1").Value = "Ext."
    Range("F1").Value = "Group #"
    Range("G1").Value = "Back Up"
    For i = 1 To LastRow Step 6
        Range("C" & Row).Value = Range("B" & i).Text
        Range("D" & Row).Value = Range("B" & i + 1).Text
        Range("E" & Row).Value = Range("B" & i + 2).Text
        Range("F" & Row).Value = Range("B" & i + 3).Text
        Range("G" & Row).Value = Range("B" & i + 4).Text
        Row = Row + 1
     If Row = 40 Then
        Call PrintHeadings
     End If
    Next i
    Columns("C:G").PrintPreview
    'Columns("C:G").ClearContents
    End Sub
    
    Public Sub PrintHeadings()
    Range("C1:G1").Font.Bold = "True"
    Range("C1").Value = "Group Name"
    Range("D1").Value = "Bill Rep"
    Range("E1").Value = "Ext."
    Range("F1").Value = "Group #"
    Range("G1").Value = "Back Up"
    'Row = 0
    Row = 3
    End Sub
    Peace of mind is found in some of the strangest places.

  11. #11
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Not sure what you mean Austen. If you only have one single Sheet, but have many pages and you have a single set of headers that you want repeated at the top of every printed page, then follow these steps ...

    File (menu) --> Page Setup..
    Sheet (tab)
    Rows to Repeat at Top --> Select entire header rows --> Ok.

    Is that what you are talking about?

  12. #12
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Thanks Zack. We can mark this one solved.
    Peace of mind is found in some of the strangest places.

Posting Permissions

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