Incrementing Week number from a set date?

satty

Board Regular
Joined
Jan 12, 2003
Messages
68
hey again people,

well i guess i have yet another problem... :oops:

i have a form, in which i want to be able to insert a date, for example, 01/04/2003 in to a textbox. i now want another text box, which can calculate the week number since this date upto now, the current date.

is this possible? hope so.

Thanx guys



Satty
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hello,

You could use this simple VBA function:

Code:
Public Function WeekNumber(CalcDate) As Long

'Returns the week number up to Calcdate.  Returns 0 if
'CalcDate is not a valid date

Dim dteFirstDayOfYear As Date

If IsDate(CalcDate) = False Then WeekNumber = 0: Exit Function

dteFirstDayOfYear = #1/1/2004#

WeekNumber = Int((CDate(CalcDate) - dteFirstDayOfYear) / 7) + 1

End Function

You can then update your second textbox based on the first using something like this:-

Code:
Private Sub txtTheDate_AfterUpdate()
Me.txtTheWeekNumber = WeekNumber(Me.txtTheDate)
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,621
Messages
6,160,879
Members
451,675
Latest member
Parlapalli

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top