ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   fill weekdays with date (https://www.excelbanter.com/excel-programming/420247-fill-weekdays-date.html)

man

fill weekdays with date
 
now i need to fill across columns. for example, today be wednesday, me
needs this week and two weeks of data

like this:

wed thu fri mon tue wed thu fri mon tue wed thu fri

on monday i need this with dates

mon tue wed thu fri mon tue wed thu fri

u get the idea,

now pls post code to fill across with dates



Bernard Liengme

fill weekdays with date
 
Enter the starting date in some cell (In the example, I will use A1)
If you want the current date use =TODAY()
In B1 type =WORKDAY(A1,1)
Copy this across the row to M1
Later you can use Help to lean how to add a list of holidays to the
worksheet and have you formula skip any holiday
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"man" wrote in message
...
now i need to fill across columns. for example, today be wednesday, me
needs this week and two weeks of data

like this:

wed thu fri mon tue wed thu fri mon tue wed thu fri

on monday i need this with dates

mon tue wed thu fri mon tue wed thu fri

u get the idea,

now pls post code to fill across with dates




royUK[_49_]

fill weekdays with date
 

Try this


Code:
--------------------
Option Explicit
Dim SourceRange As Range
Dim FillRange As Range
Dim StartRange As Range
Dim ThisCl As Range
Dim d
Dim ThisDate As Date
Sub FillRangeWeekdays()
Set ThisCl = ActiveCell
g_sFillDirection = "Right"
If Not IsDate(ThisCl) Then
MsgBox "Enter the first date", vbInformation, _
"First day of list"

Else:
'fill a range of dates with consecutive dates
d = InputBox("How many days do you want to add" & vbNewLine & vbNewLine _
& "Weekends will not be included")
If d = 0 Or d < 0 Or d = vbNullString Then GoTo ErrExit
'create a list of dates weekdays only fill to right
If ThisCl.End(xlToRight).Column < ThisCl.Column + d Then
Call MsgBox("There are insufficient Columns for this action", _
vbExclamation, "Error")
Exit Sub
End If
ThisCl.Offset(0, 1).Value = ThisCl.Value + 1
Set SourceRange = Range(ThisCl, ThisCl.Offset(0, 1))
Set FillRange = Range(ThisCl, ThisCl.Offset(0, (d - 1)))
SourceRange.AutoFill FillRange, xlFillWeekdays

FillRange.Columns.AutoFit
ErrExit:
End If
Application.ScreenUpdating = True
End Sub
--------------------


I am adding this function to the calendar form taht is in the Downloads
section Watch for a newer version soon


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site
' (http://www.excel-it.com)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=31453



All times are GMT +1. The time now is 01:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com