ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   DateAdd (https://www.excelbanter.com/excel-programming/364605-dateadd.html)

johnboy

DateAdd
 
Hi all,
I have a combobox on a form which I am trying to populate with week ending
dates (Sunday) from a fixed start point to a current date contained in a cell.

I have put together the following code but it is not giving the required
result. can someone be kind engough to tell me where I have gone wrong please.
Many thanks

Private Sub UserForm_Initialize()
Dim startweek As Date
Dim thisweek As Date
startweek = "04/06/2006"
thisweek = ThisWorkbook.Worksheets("FormData").Range("K8").Va lue

With ComboBox1
.Clear
For NextDate = startweek To thisweek

WeekDate = NextDate
IntervalType = "ww"
Number = 1

'change weekending to next sunday
NextDate = DateAdd(IntervalType, Number, WeekDate)
.AddItem Format(NextDate, "dd/mm/yyyy")
Next NextDate
End With
End Sub

--
JB

Bob Phillips

DateAdd
 
Private Sub UserForm_Initialize()
Dim startweek As Date
Dim thisweek As Date
startweek = "04/06/2006"
thisweek = ThisWorkbook.Worksheets("FormData").Range("K8").Va lue

With ComboBox1
.Clear
NextDate = DateValue(startweek)
Do

WeekDate = NextDate
IntervalType = "ww"
Number = 1

'change weekending to next sunday
NextDate = DateAdd(IntervalType, Number, WeekDate)
.AddItem Format(NextDate, "dd/mm/yyyy")
Loop Until NextDate thisweek
End With
End Sub



--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"johnboy" wrote in message
...
Hi all,
I have a combobox on a form which I am trying to populate with week ending
dates (Sunday) from a fixed start point to a current date contained in a

cell.

I have put together the following code but it is not giving the required
result. can someone be kind engough to tell me where I have gone wrong

please.
Many thanks

Private Sub UserForm_Initialize()
Dim startweek As Date
Dim thisweek As Date
startweek = "04/06/2006"
thisweek = ThisWorkbook.Worksheets("FormData").Range("K8").Va lue

With ComboBox1
.Clear
For NextDate = startweek To thisweek

WeekDate = NextDate
IntervalType = "ww"
Number = 1

'change weekending to next sunday
NextDate = DateAdd(IntervalType, Number, WeekDate)
.AddItem Format(NextDate, "dd/mm/yyyy")
Next NextDate
End With
End Sub

--
JB




johnboy

DateAdd
 
bob,
thanks for quick reply & solving for me! - your help is very much
appreciated.
--
JB


"Bob Phillips" wrote:

Private Sub UserForm_Initialize()
Dim startweek As Date
Dim thisweek As Date
startweek = "04/06/2006"
thisweek = ThisWorkbook.Worksheets("FormData").Range("K8").Va lue

With ComboBox1
.Clear
NextDate = DateValue(startweek)
Do

WeekDate = NextDate
IntervalType = "ww"
Number = 1

'change weekending to next sunday
NextDate = DateAdd(IntervalType, Number, WeekDate)
.AddItem Format(NextDate, "dd/mm/yyyy")
Loop Until NextDate thisweek
End With
End Sub



--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"johnboy" wrote in message
...
Hi all,
I have a combobox on a form which I am trying to populate with week ending
dates (Sunday) from a fixed start point to a current date contained in a

cell.

I have put together the following code but it is not giving the required
result. can someone be kind engough to tell me where I have gone wrong

please.
Many thanks

Private Sub UserForm_Initialize()
Dim startweek As Date
Dim thisweek As Date
startweek = "04/06/2006"
thisweek = ThisWorkbook.Worksheets("FormData").Range("K8").Va lue

With ComboBox1
.Clear
For NextDate = startweek To thisweek

WeekDate = NextDate
IntervalType = "ww"
Number = 1

'change weekending to next sunday
NextDate = DateAdd(IntervalType, Number, WeekDate)
.AddItem Format(NextDate, "dd/mm/yyyy")
Next NextDate
End With
End Sub

--
JB






All times are GMT +1. The time now is 04:49 AM.

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