Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Initializing values in a Listbox on a Form

Assume cells a1:a3 the rowsource for LISTBOX1 contain
01/01/2008
02/01/2008
03/01/2008
I can code-
userform1.listbox1.value=range("a2").value
This wokks just fine.
If, however, I change the format of cells a1:a3 to a date format, the above
code will now fail. The failure also holds true if I use text instead of
value in the above line of code. The failure persists with any formatting
other than "General".
Any suggestions would be appreciated. I want to show my user a formatted
date, not a date serial number.
Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default Initializing values in a Listbox on a Form

UserForm1.ListBox1.RowSource = ("A1:A3")

"Marvin Buzz" wrote:

Assume cells a1:a3 the rowsource for LISTBOX1 contain
01/01/2008
02/01/2008
03/01/2008
I can code-
userform1.listbox1.value=range("a2").value
This wokks just fine.
If, however, I change the format of cells a1:a3 to a date format, the above
code will now fail. The failure also holds true if I use text instead of
value in the above line of code. The failure persists with any formatting
other than "General".
Any suggestions would be appreciated. I want to show my user a formatted
date, not a date serial number.
Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Initializing values in a Listbox on a Form

If I want the second item in the list, then I'd use:

Me.ListBox1.List = Worksheets("sheet1").Range("a1:a10").Value
Me.ListBox1.ListIndex = 1

(0 is the first item, 1 is the second, ...)



Marvin Buzz wrote:

Assume cells a1:a3 the rowsource for LISTBOX1 contain
01/01/2008
02/01/2008
03/01/2008
I can code-
userform1.listbox1.value=range("a2").value
This wokks just fine.
If, however, I change the format of cells a1:a3 to a date format, the above
code will now fail. The failure also holds true if I use text instead of
value in the above line of code. The failure persists with any formatting
other than "General".
Any suggestions would be appreciated. I want to show my user a formatted
date, not a date serial number.
Thanks.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Initializing values in a Listbox on a Form

If I change the format of the data in sheet1, the listbox does not show the
data in the new format.

My objective is to have two listboxes, and populate the second box based on
the value of the first. For example, box 2 should always have a higher value
than box1. If that is not true, I want to place the next listed value from
box 1 into box 2. I then need both values so that I can use them as a filter
in another worksheet.


"Dave Peterson" wrote:

If I want the second item in the list, then I'd use:

Me.ListBox1.List = Worksheets("sheet1").Range("a1:a10").Value
Me.ListBox1.ListIndex = 1

(0 is the first item, 1 is the second, ...)



Marvin Buzz wrote:

Assume cells a1:a3 the rowsource for LISTBOX1 contain
01/01/2008
02/01/2008
03/01/2008
I can code-
userform1.listbox1.value=range("a2").value
This wokks just fine.
If, however, I change the format of cells a1:a3 to a date format, the above
code will now fail. The failure also holds true if I use text instead of
value in the above line of code. The failure persists with any formatting
other than "General".
Any suggestions would be appreciated. I want to show my user a formatted
date, not a date serial number.
Thanks.


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Initializing values in a Listbox on a Form

You can use .additem to add items to the listbox in the format you like. And
you can use the _change event for the first listbox to change the second listbox
entries.

I don't quite understand what you're doing, but this may help.

Option Explicit
Private Sub ListBox1_Change()

Dim iCtr As Long

Me.ListBox2.Clear

If Me.ListBox1.ListIndex < 0 Then
Exit Sub 'nothing selected
End If

With Me.ListBox1
For iCtr = .ListIndex + 1 To .ListCount - 1
Me.ListBox2.AddItem .List(iCtr)
Next iCtr
End With
End Sub
Private Sub UserForm_Initialize()

Dim myRng As Range
Dim myCell As Range

With Worksheets("sheet1")
Set myRng = .Range("a1:A10")
End With

For Each myCell In myRng.Cells
Me.ListBox1.AddItem Format(myCell.Value, "mmmm dd, yyyy")
Next myCell
End Sub


Marvin Buzz wrote:

If I change the format of the data in sheet1, the listbox does not show the
data in the new format.

My objective is to have two listboxes, and populate the second box based on
the value of the first. For example, box 2 should always have a higher value
than box1. If that is not true, I want to place the next listed value from
box 1 into box 2. I then need both values so that I can use them as a filter
in another worksheet.

"Dave Peterson" wrote:

If I want the second item in the list, then I'd use:

Me.ListBox1.List = Worksheets("sheet1").Range("a1:a10").Value
Me.ListBox1.ListIndex = 1

(0 is the first item, 1 is the second, ...)



Marvin Buzz wrote:

Assume cells a1:a3 the rowsource for LISTBOX1 contain
01/01/2008
02/01/2008
03/01/2008
I can code-
userform1.listbox1.value=range("a2").value
This wokks just fine.
If, however, I change the format of cells a1:a3 to a date format, the above
code will now fail. The failure also holds true if I use text instead of
value in the above line of code. The failure persists with any formatting
other than "General".
Any suggestions would be appreciated. I want to show my user a formatted
date, not a date serial number.
Thanks.


--

Dave Peterson


--

Dave Peterson
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
Initializing Form Controls PosseJohn Excel Programming 7 June 23rd 08 01:24 PM
finding values and put them in a listbox on visual basic form Frank M Excel Programming 0 November 12th 07 10:48 AM
Initializing control values of a form TimK Excel Programming 1 September 29th 06 06:34 AM
Fill values into a listbox matching selected values from a combobox Jon[_19_] Excel Programming 4 January 25th 05 04:25 PM
Initializing a Form with multiple forms embedded bforster1 Excel Programming 2 July 14th 04 07:42 PM


All times are GMT +1. The time now is 03:32 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"