View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Nick Hodge[_2_] Nick Hodge[_2_] is offline
external usenet poster
 
Posts: 185
Default Date Formatting Within A Combo Box On A Userform

Div

You can use the Initialize() event of the userform like so (Change the name
of the combobox to the name you have)

Private Sub UserForm_Initialize()
Dim cb As ComboBox
Dim x As Integer, iDayNo As Integer

Set cb = Me.ComboBox1

For x = 0 To 27
iDayNo = Application.WorksheetFunction.Weekday(Date - x, 2)
If iDayNo < 7 Then
cb.AddItem Format(Date - x, "dd/mm/yyyy")
End If
Next x
cb.ListIndex = 0
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
web:
www.excelusergroup.org
web: www.nickhodge.co.uk





"Div via OfficeKB.com" <u43652@uwe wrote in message
news:845669fb928b0@uwe...
Many thanks Nick. Being new to any form of programming I had pondered over
the solution for many weeks. About 2 hours after posting my original
message
I got to the conclusion with regards the use of formatting. However your
solution is far more elegant and efficient so again thanks.

If it's not too much of a cheek what I really had desired was the
following
(again within Excel 2007):

On a userform I would like to populate a combobox with dates for the
previous
28 days starting from the current date (i.e. todays date) but absent from
that list is any day which is a Sunday - all via VBA.

Any ideas?

Regards - Div

Nick Hodge wrote:
Div

It appears as a serial date where? If it is on a worksheet just format it,
if it arrives into a variable in your code you may need to specifically
parse it, e.g

Private Sub ComboBox1_Change()
Dim myUKDate As String
myUKDate = Format(Me.ComboBox1.Value, "dd/mm/yyyy")
MsgBox myUKDate
End Sub
Hi All,

[quoted text clipped - 10 lines]

Regards - Div


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200805/1