+ Reply to Thread
Results 1 to 9 of 9

automatically fill cell with end of date monthly

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-11-2009
    Location
    Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    252

    automatically fill cell with end of date monthly

    hi,
    I have a monthly reports generated by the button to create a new sheet,I want the new sheet A1 in cell filled with the date of the end of the month, Can the code that can automatically create entries, the sheet name is " jan10" ( end of date is jan 31), "feb10" (feb28).etc

    thanks in advance
    herukuncahyono
    Last edited by herukuncahyono; 04-27-2010 at 08:40 PM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: automatically fill cell with end of date monthly

    You don't stipulate how you're creating the new sheet but let's assume something along the lines of:

    With Sheets.Add
        .Name = "Feb10" 'presumably this is a variable of some sort
        .Cells(1, "A") = DateAdd("m", 1, "01-" & Left(.Name, 3) & "-" & Right(.Name, 2)) - 1
    End With
    above assumes a consistent naming pattern of mmmyy

  3. #3
    Forum Contributor
    Join Date
    03-11-2009
    Location
    Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    252

    Re: automatically fill cell with end of date monthly

    hi DonkeyOte,

    Thanks for the response, sorry to make you confused ,I have userform with textbox & comandbutton to generate new sheet by fill name on textbox
    Sheets("form").Copy After:=Sheets(Sheets.Count)
        Sheets("form (2)").Name = UserForm1.TextBox1.Text
    Can the two codes above combined

    I really appreaciate your quick replies
    regards
    herukuncahyono

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: automatically fill cell with end of date monthly

    Without knowing how you're controlling data entry on the UserForm (or indeed if) - perhaps:

    Sheets("form").Copy After:=Sheets(Sheets.Count)
    With ActiveSheet
        .Name = UserForm1.TextBox1.Text
        .Cells(1, "A") = DateAdd("m", 1, "01-" & Left(.Name, 3) & "-" & Right(.Name, 2)) - 1
    End With
    though as implied you will need to validate the TextBox string first - so as to ensure consistency.

  5. #5
    Forum Contributor
    Join Date
    03-11-2009
    Location
    Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    252

    Re: automatically fill cell with end of date monthly

    hi DonkeyOte,

    for more details, I attach an example.I hope you more easily understand what I mean.

    regards
    herukuncahyono
    Attached Files Attached Files

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: automatically fill cell with end of date monthly

    ...and the problem is what exactly ?

    I was simply making the point that unless you control the entry text the code could debug - eg I type in "apple" and hit OK.

+ 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