Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Excel2000 VBA: First workday of month

Hi

What is the best way to calculate 1st workday of any month (holidays must be
counted too)?

At moment I have a solution, where a list of dates for some amount of years
is created, with additional column where all dates are labeled as "workday",
"weekend", or "holiday". The code is looking for 1st workday in this list,
starting from 1st of month.

Probably a slightly better solution will be, where the list contains only
holidays. The code will be look for 1st date to be not weekend and not
present in holidays list in given month.

On worksheet, I can easily calculate the 1st workday of month using WORKDAY
function {=WORKDAY(DATE(Year, Month, 0),1,Holydays)}. But it seems, that I
can't use functions from Analysis Toolpack in VBA! Am I right about this, or
is there a way?


Arvi Laanemets


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel2000 VBA: First workday of month

try using the eomonth function then +1
also you may need to nest in a vlookup if statement to check whether that
date returned is holiday (from the list of holiday dates).

"Arvi Laanemets" wrote in message
...
Hi

What is the best way to calculate 1st workday of any month (holidays must
be
counted too)?

At moment I have a solution, where a list of dates for some amount of
years
is created, with additional column where all dates are labeled as
"workday",
"weekend", or "holiday". The code is looking for 1st workday in this list,
starting from 1st of month.

Probably a slightly better solution will be, where the list contains only
holidays. The code will be look for 1st date to be not weekend and not
present in holidays list in given month.

On worksheet, I can easily calculate the 1st workday of month using
WORKDAY
function {=WORKDAY(DATE(Year, Month, 0),1,Holydays)}. But it seems, that I
can't use functions from Analysis Toolpack in VBA! Am I right about this,
or
is there a way?


Arvi Laanemets




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel2000 VBA: First workday of month

dte = DateSerial(Year(Date),Month(Date)-1,0)
v = Application.Run "ATPVBAEN.xla!Workdate" dte,1,Range("HolyDays")

if ATPVBAEN is loaded in tools addins. (analysis toolpak for VBA)
--
Regards,
Tom Ogilvy



"Arvi Laanemets" wrote in message
...
Hi

What is the best way to calculate 1st workday of any month (holidays must

be
counted too)?

At moment I have a solution, where a list of dates for some amount of

years
is created, with additional column where all dates are labeled as

"workday",
"weekend", or "holiday". The code is looking for 1st workday in this list,
starting from 1st of month.

Probably a slightly better solution will be, where the list contains only
holidays. The code will be look for 1st date to be not weekend and not
present in holidays list in given month.

On worksheet, I can easily calculate the 1st workday of month using

WORKDAY
function {=WORKDAY(DATE(Year, Month, 0),1,Holydays)}. But it seems, that I
can't use functions from Analysis Toolpack in VBA! Am I right about this,

or
is there a way?


Arvi Laanemets




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Excel2000 VBA: First workday of month

Thanks!


"Tom Ogilvy" wrote in message
...
dte = DateSerial(Year(Date),Month(Date)-1,0)
v = Application.Run "ATPVBAEN.xla!Workdate" dte,1,Range("HolyDays")

if ATPVBAEN is loaded in tools addins. (analysis toolpak for VBA)


It must be! I think I'll include a check routine for this into procedure.
And here my second question. I can check for Analysis Toolpack being
installed through
.....
Application.AddIns(i).Name = "ANALYS32.XLL" And
Application.AddIns(i).Installed = True
....

where all AddInns are checked until Analysis Toolpack is found (or not
found). I didn't find any way to check for Analysis Toolpack directly.
Exists there such a way at all?


Arvi Laanemets


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel2000 VBA: First workday of month

I left out a comma - all arguments to the ATP function, event the first, are
set off by commas since they are all arguments to Application.Run


dte = DateSerial(Year(Date),Month(Date)-1,0)
v = Application.Run "ATPVBAEN.xla!Workdate",dte,1,Range("HolyDays" )

--
Regards,
Tom Ogilvy


"Arvi Laanemets" wrote in message
...
Thanks!


"Tom Ogilvy" wrote in message
...
dte = DateSerial(Year(Date),Month(Date)-1,0)
v = Application.Run "ATPVBAEN.xla!Workdate" dte,1,Range("HolyDays")

if ATPVBAEN is loaded in tools addins. (analysis toolpak for VBA)


It must be! I think I'll include a check routine for this into procedure.
And here my second question. I can check for Analysis Toolpack being
installed through
....
Application.AddIns(i).Name = "ANALYS32.XLL" And
Application.AddIns(i).Installed = True
...

where all AddInns are checked until Analysis Toolpack is found (or not
found). I didn't find any way to check for Analysis Toolpack directly.
Exists there such a way at all?


Arvi Laanemets






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel2000 VBA: First workday of month

OK, just noticed I misspelled Workday [ bad day :-( ]. Here is a tested
version to demonstrate - demonstrated in the immediate window:

dte = DateSerial(Year(Date),Month(Date)-1,0)
v = Application.Run( "ATPVBAEN.xla!Workday", dte, 1, Range("HolyDays"))
[GetMacroRegId] 'WORKDAY' <
[GetMacroRegId] 'WORKDAY' - '2142634039'
? format(v,"mmm dd,yyyy")
May 02,2005

the lines with [GetMacroRegId] are produced by the ATPVBAEN and are just
debris.

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
I left out a comma - all arguments to the ATP function, event the first,

are
set off by commas since they are all arguments to Application.Run


dte = DateSerial(Year(Date),Month(Date)-1,0)
v = Application.Run "ATPVBAEN.xla!Workdate",dte,1,Range("HolyDays" )

--
Regards,
Tom Ogilvy


"Arvi Laanemets" wrote in message
...
Thanks!


"Tom Ogilvy" wrote in message
...
dte = DateSerial(Year(Date),Month(Date)-1,0)
v = Application.Run "ATPVBAEN.xla!Workdate" dte,1,Range("HolyDays")

if ATPVBAEN is loaded in tools addins. (analysis toolpak for VBA)


It must be! I think I'll include a check routine for this into

procedure.
And here my second question. I can check for Analysis Toolpack being
installed through
....
Application.AddIns(i).Name = "ANALYS32.XLL" And
Application.AddIns(i).Installed = True
...

where all AddInns are checked until Analysis Toolpack is found (or not
found). I didn't find any way to check for Analysis Toolpack directly.
Exists there such a way at all?


Arvi Laanemets






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default Excel2000 VBA: First workday of month

Hi Tom

I tried your solution now, and after some modifying it worked as needed. My
code (it reads indefinite number of column headers from row 1 starting from
F1 in a single-sheet source workbook - text strings in format "yyyy-mm" -
and saves them into an array as datestrings of 1st workday of according
month) is now:
.....
Dim arrMonths() As Variant
....
varSource = [SourceWorkbook]
rngHolidays = [Holidays]
.....
ColNum = Workbooks(varSource).Sheets(1).UsedRange.Columns.C ount
.....
ReDim arrMonths(1 To ColNum-5) As Variant
j = 0
For i = 6 To ColNum
j = j + 1
xMonth = Workbooks(varSource).Sheets(1).Range("A1").Offset( 0,
i - 1)
dte = DateSerial(Mid(xMonth, 1, 4), Mid(xMonth, 6, 2), 0)
xDate = Application.Run("ATPVBAEN.xla!Workday", dte, 1,
rngHolidays)
arrMonths(j) = Format(xDate, "mm-dd-yy")
Next i
.....

(And at start I missed, that not Analysis Toolpack, but Analysis Toolpack
for VBA is needed)


Thanks again!
--
Arvi Laanemets
( My real mail address: arvil<attarkon.ee )



"Tom Ogilvy" wrote in message
...
OK, just noticed I misspelled Workday [ bad day :-( ]. Here is a tested
version to demonstrate - demonstrated in the immediate window:

dte = DateSerial(Year(Date),Month(Date)-1,0)
v = Application.Run( "ATPVBAEN.xla!Workday", dte, 1, Range("HolyDays"))
[GetMacroRegId] 'WORKDAY' <
[GetMacroRegId] 'WORKDAY' - '2142634039'
? format(v,"mmm dd,yyyy")
May 02,2005

the lines with [GetMacroRegId] are produced by the ATPVBAEN and are just
debris.

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
I left out a comma - all arguments to the ATP function, event the first,

are
set off by commas since they are all arguments to Application.Run


dte = DateSerial(Year(Date),Month(Date)-1,0)
v = Application.Run "ATPVBAEN.xla!Workdate",dte,1,Range("HolyDays" )

--
Regards,
Tom Ogilvy


"Arvi Laanemets" wrote in message
...
Thanks!


"Tom Ogilvy" wrote in message
...
dte = DateSerial(Year(Date),Month(Date)-1,0)
v = Application.Run "ATPVBAEN.xla!Workdate" dte,1,Range("HolyDays")

if ATPVBAEN is loaded in tools addins. (analysis toolpak for VBA)

It must be! I think I'll include a check routine for this into

procedure.
And here my second question. I can check for Analysis Toolpack being
installed through
....
Application.AddIns(i).Name = "ANALYS32.XLL" And
Application.AddIns(i).Installed = True
...

where all AddInns are checked until Analysis Toolpack is found (or not
found). I didn't find any way to check for Analysis Toolpack directly.
Exists there such a way at all?


Arvi Laanemets








Reply
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
Finding second-to-last workday of month Brian Excel Worksheet Functions 4 December 22nd 09 12:17 AM
Count the number of workday in a month YY san.[_2_] Excel Worksheet Functions 5 October 28th 09 08:31 PM
Compare & sum previous month production by workday. Cindy Excel Discussion (Misc queries) 9 April 28th 09 08:58 AM
workday with month functions Monique Excel Worksheet Functions 5 October 30th 07 01:19 AM
Excel inventory Sheet for workday month Monique Excel Worksheet Functions 1 April 26th 07 12:02 AM


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

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

About Us

"It's about Microsoft Excel"