+ Reply to Thread
Results 1 to 3 of 3

Need help of getting current month date from start to end!!

Hybrid View

  1. #1
    Registered User
    Join Date
    05-14-2012
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    4

    Need help of getting current month date from start to end!!

    Hi,

    I have used the below code to get the current month date, but it is filling the date until the last cell i.e. 1 may 2012 to "last row date" something like 3-jan- 4015. Kindly help me to get the current month dates alone in the spread sheet.


    Sub CurrentMonthdate()
    'MsgBox Month(Now)
    'MsgBox Application.WorksheetFunction.EoMonth(Now(), 0)
    Range("A2").Select
    
    ActiveCell = Application.WorksheetFunction.EOMonth(Now(), -1) + 1
    ActiveCell.NumberFormat = "mm/dd/yyyy"
    While (ActiveCell <> Application.WorksheetFunction.EOMonth(Now(), 0))
        ActiveCell.Offset(1, 0).Select
        ActiveCell = ActiveCell.Offset(-1, 0) + 1
        ActiveCell.NumberFormat = "mm/dd/yyyy"
    Wend
    
    
    End Sub
    Last edited by arlu1201; 06-08-2012 at 06:12 AM. Reason: Use code tags in future.

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Need help of getting current month date from start to end!!

    Option Explicit
    
    Sub Create_Dates()
    
        Dim i As Long, y As Long, m As Long
        
        y = Year(Date)
        m = Month(Date)
        
        Application.ScreenUpdating = False
        
        For i = 1 To Application.WorksheetFunction.EoMonth(Date, 0) - Application.WorksheetFunction.EoMonth(Date, -1)
            Cells(i, "A") = Format(DateSerial(y, m, i), "mm/dd/yyyy")
        Next i
        
        Application.ScreenUpdating = True
    
    End Sub
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Registered User
    Join Date
    05-14-2012
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Need help of getting current month date from start to end!!

    Hi Palmetto,

    Thanks for your reply

    I am facing the issues with the macro wrong number of arguments or invalid property assignment excel macro....when i am using in the other worksheet its working fine

    I am using below code in my worksheet
    Sub Create_Dates()

    Dim i As Long, y As Long, m As Long

    y = Year(Date)
    m = Month(Date)

    Application.ScreenUpdating = False

    Sheets.add
    ActiveSheet.Name = "Sheet2"
    Sheets("Sheet2").Select
    'Range("A2").Select
    For i = 1 To Application.WorksheetFunction.EOMonth(Date, 0) - Application.WorksheetFunction.EOMonth(Date, -1)
    Cells(i, "A") = Format(DateSerial(y, m, i), "mm/dd/yyyy")
    Next i

    Application.ScreenUpdating = True
    Range("A1").Select
    Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove

    Range("A1").Value = "Date"
    'Range("B1").Value = "Used"
    'Range("C1").Value = "Max"
    'Range("D1").Value = "Percentage"
    Sheets.add
    ActiveSheet.Name = "Sheet3"
    End Sub

    Please advice me anything is missing here

+ 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