Consulting

Results 1 to 10 of 10

Thread: Putting A Date Into A Cell

  1. #1

    Putting A Date Into A Cell

    Hi

    I have a spreadsheet with four tabs. I would like to place todays (=TODAY()) date in cell D3 of each of these tabs. I already run a programme on the spreadsheet which formats the sheet etc. how I want it before printout.

    Can anyone help?

    Alan

  2. #2
    Hi All

    Wow!!! I must be learning something from you guys as I have just solved the problem myself. I know it wasnt that difficult but to a novice like me it a big step forward.

    Alan

  3. #3
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Why not post your solution - it could help someone else in the future!

  4. #4
    Ok, here it is but I doubt it is ground breaking and there is probably a better way to do it but hey, it works.

    Sub DateInsert()
    '
    Sheets("Sheet1").Select
    Range("D3").Select
    ActiveCell.FormulaR1C1 = "=TODAY()"
    Selection.NumberFormat = "d-mmm-yy"
    Sheets("Sheet2").Select
    Range("F3").Select
    ActiveCell.FormulaR1C1 = "=TODAY()"
    Selection.NumberFormat = "d-mmm-yy"
    Sheets("Sheet3").Select
    Range("D3").Select
    ActiveCell.FormulaR1C1 = "=TODAY()"
    Selection.NumberFormat = "d-mmm-yy"
    Sheets("Sheet4").Select
    Range("D3").Select
    ActiveCell.FormulaR1C1 = "=TODAY()"
    Selection.NumberFormat = "d-mmm-yy"

    End Sub

    Alan

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You can tidy that up

    [vba]

    Sub DateInsert()
    '
    With Sheets("Sheet1").Range("D3")
    .FormulaR1C1 = "=TODAY()"
    .NumberFormat = "d-mmm-yy"
    End With
    With Sheets("Sheet2").Range("F3")
    .FormulaR1C1 = "=TODAY()"
    .NumberFormat = "d-mmm-yy"
    End With
    With Sheets("Sheet3").Range("D3")
    .FormulaR1C1 = "=TODAY()"
    .NumberFormat = "d-mmm-yy"
    End With
    With Sheets("Sheet4").Range("D3")
    .FormulaR1C1 = "=TODAY()"
    .NumberFormat = "d-mmm-yy"
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Alan

    Do you want the date to be static?

  7. #7
    Thanks xld. What to you mean by static Norie?

  8. #8
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Well the code you have is putting a formula into a cell.

    That formula will probably update every time you open the workbook.

    So tomorrow it will read 31-Jul-2007.

  9. #9
    I see. In this case this is exactly what I need. I get reports every Monday and they need to dated all the same. At the moment the people sending the reports either don't date them or date them the time they write the report, or even worse, copy an old report and don't change the date. This way when I rum my macro on the reports they all get dated the same.

    Just so I know, how would you make it a static date?

    Alan

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub DateInsert()
    '
    With Sheets("Sheet1").Range("D3")
    .Value = Date
    .NumberFormat = "d-mmm-yy"
    End With
    With Sheets("Sheet2").Range("F3")
    .Value = Date
    .NumberFormat = "d-mmm-yy"
    End With
    With Sheets("Sheet3").Range("D3")
    .Value = Date
    .NumberFormat = "d-mmm-yy"
    End With
    With Sheets("Sheet4").Range("D3")
    .Value = Date
    .NumberFormat = "d-mmm-yy"
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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