Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6
Default User form question

Hi all,

I have created a userform with a list of dates to choose from in a List Box;
the user can choose only one date, but in case they don't, there is always a
default date selected, being the last item on the list. How can I achieve
this?

Thanks much in advance!


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 95
Default User form question

Haas,

Try something like the following:

Dim Result As String
Dim ResultDate As Date
With Me.ListBox1
If .ListIndex < 0 Then ' none selected
Result = .List(.ListCount - 1)
Else
Result = .List(.ListIndex)
End If
End With
ResultDate = DateValue(Result)
MsgBox ResultDate


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Haas" wrote in message
...
Hi all,

I have created a userform with a list of dates to choose from in a List

Box;
the user can choose only one date, but in case they don't, there is always

a
default date selected, being the last item on the list. How can I achieve
this?

Thanks much in advance!




  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,327
Default User form question

Hi

Set the style to "list" and make sure something (=last item) is selected before display.
Something like

Private Sub UserForm_Initialize()
' This is it part 1 :
ComboBox1.Style = fmStyleDropDownList
' List fill. Whatever.
ComboBox1.AddItem "1"
ComboBox1.AddItem "2"
ComboBox1.AddItem "3"
ComboBox1.AddItem "4"
' This is it pt 2 :
ComboBox1.ListIndex = ComboBox1.ListCount - 1
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Haas" wrote in message
...
Hi all,

I have created a userform with a list of dates to choose from in a List Box;
the user can choose only one date, but in case they don't, there is always a
default date selected, being the last item on the list. How can I achieve
this?

Thanks much in advance!




  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 493
Default User form question

in your userform initialization code:

ListBox1.ListIndex = ListBox1.ListCount - 1

In article ,
"Haas" wrote:

Hi all,

I have created a userform with a list of dates to choose from in a List Box;
the user can choose only one date, but in case they don't, there is always a
default date selected, being the last item on the list. How can I achieve
this?

Thanks much in advance!


  #5   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,327
Default User form question

Doh ! Listbox of course. My mistake, sorry, I was thinking combobox'ed. Once
something is preselected in a listbox then something will always be, as in
the other replies.

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Harald Staff" skrev i melding
...
Hi

Set the style to "list" and make sure something (=last item) is selected

before display.
Something like

Private Sub UserForm_Initialize()
' This is it part 1 :
ComboBox1.Style = fmStyleDropDownList
' List fill. Whatever.
ComboBox1.AddItem "1"
ComboBox1.AddItem "2"
ComboBox1.AddItem "3"
ComboBox1.AddItem "4"
' This is it pt 2 :
ComboBox1.ListIndex = ComboBox1.ListCount - 1
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Haas" wrote in message
...
Hi all,

I have created a userform with a list of dates to choose from in a List

Box;
the user can choose only one date, but in case they don't, there is

always a
default date selected, being the last item on the list. How can I

achieve
this?

Thanks much in advance!






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Form question ah Excel Discussion (Misc queries) 1 November 5th 07 10:40 AM
user form question: text box to display result BigPig Excel Discussion (Misc queries) 0 February 28th 06 12:33 AM
user form question: text box to display result BigPig Excel Worksheet Functions 0 February 25th 06 08:17 PM
User form question Gareth[_3_] Excel Programming 2 November 20th 03 09:37 PM
User form question Gareth[_3_] Excel Programming 1 October 29th 03 06:07 PM


All times are GMT +1. The time now is 05:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"