LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Lousy routine to get the first available day of the month

I have a worksheet with dates and data. The date column only includes
business days from different countries.

I need to retrieve the first available business days for every month
and every year.

Here is my lousy yet working code.

I parse the A column, where the date reside) into 3 (month, day and
year) and sort the worksheet by day (column b). Then I autofilter each
month, autofilter each year and finally copy the results. I loop for
each month and each year.

It works but looks there must be a better and faster way.

BTW, I’m not a programmer, which explains the complicated code:

Application.ScreenUpdating = False

Columns("B:C").Insert Shift:=xlToRight
Columns("A:A").TextToColumns Destination:=Range("A1"),
DataType:=xlDelimited, TextQualifier:=xlNone, OtherChar:="/"
Columns("A:C").NumberFormat = "General"
Range("A1") = "month"
Range("B1") = "day"
Range("C1") = "year"

c = 1 'month
yhigh = Application.Max(Columns("C:C")) + 1 'the highest year

Range(("A1"), Range("A1").SpecialCells(xlLastCell)).Select
With Selection
.Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlYes
Do Until c = 13 '12 = December
ylow = Application.Min(Columns("C:C")) 'reset the lowest year
.AutoFilter Field:=1, Criteria1:=c
Do Until ylow = yhigh
.AutoFilter Field:=3, Criteria1:=ylow
Selection.Copy
Sheets("data1").Select
ActiveCell.PasteSpecial xlPasteAll
ActiveCell.EntireRow.Delete
ActiveCell.Offset(1, 0).Activate
Range(ActiveCell,
ActiveCell.SpecialCells(xlLastCell)).Delete
Sheets("data").Select
ylow = ylow + 1 'go through each year for specific month
(c)
Loop
c = c + 1 'goto next month
Loop
End With

Sheets("data1").Select

Range(("B1"), Range("B1").End(xlDown)) = 1 'each first day of the
month must equat 1
Range(("A1"), Range("A1").SpecialCells(xlLastCell)).Sort
Key1:=Range("C1"), Order1:=xlAscending, Key2:=Range("A1"),
Order2:=xlAscending, Header:=xlYes
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check Date, Include dates from rest of month and all of next month Patrick Molloy Excel Programming 3 July 28th 09 05:08 PM
excel to make the days cary over month to month automaticly GARY New Users to Excel 1 April 19th 08 06:05 PM
Excel 2003 month to month data change grid Chad[_2_] Excel Discussion (Misc queries) 2 February 15th 08 01:36 AM
copy worksheet from previous month and rename to current month Dan E. Excel Programming 4 December 8th 05 09:40 PM
transfer cell $ amount to other sheet month-to-month without overc Colin2u Excel Discussion (Misc queries) 1 July 28th 05 02:36 AM


All times are GMT +1. The time now is 02:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"