DateAdd

G

Guest

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").Value

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
 
B

Bob Phillips

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

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top