Hi,
First you Can give Name ranges instead of Static Range like B1:B31 Second : You can create a Function for these lines to reduce the Lines from your code With myrange.Cells(1) .Value = DateSerial(Year(Date), month(Date), 1) .AutoFill Destination:=myrange, Type:=xlFillDays End With Except these things its good Regards Rajan verma +91 7838100659 [IM-Gtalk] From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com] On Behalf Of Darwin Chan Sent: 17 May 2012 11:45 To: excel-macros@googlegroups.com Subject: $$Excel-Macros$$ Ask for improvement for procedure for date filling Dear all, I have written a simple procedure to fill cells with dates, it depends on the current month and decide the range of the cells. Can anyone suggest any room for improvement for my code? Sub monthfill() Dim myrange As Range Dim mth As Integer Cells.Clear mth = month(Date) Select Case mth Case 1, 3, 5, 7, 8, 10, 12 Set myrange = Range("B1: B31") With myrange.Cells(1) .Value = DateSerial(Year(Date), month(Date), 1) .AutoFill Destination:=myrange, Type:=xlFillDays End With Case 4, 6, 9, 11 Set myrange = Range("B1: B30") With myrange.Cells(1) .Value = DateSerial(Year(Date), month(Date), 1) .AutoFill Destination:=myrange, Type:=xlFillDays End With Case 2 Set myrange = Range("B1: B28") With myrange.Cells(1) .Value = DateSerial(Year(Date), month(Date), 1) .AutoFill Destination:=myrange, Type:=xlFillDays End With End Select Set myrange = Nothing End Sub Darwin -- FORUM RULES (986+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ---------------------------------------------------------------------------- -------------------------- To post to this group, send email to excel-macros@googlegroups.com -- FORUM RULES (986+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ------------------------------------------------------------------------------------------------------ To post to this group, send email to excel-macros@googlegroups.com