Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA Combo Box

I normally use a format control drop down box. This is my first time using a
VBA Combo Box. I have two questions that are probably very basic but I can't
get this figured out.

I am using ListFillRange to define a column that has dates. This is
working, however the selection is displayed as a seriel number.

How can I format the display of the user's selection to be in a mmm-yy format?

Also, how do I link a cell to pull the selection from the combo-box?

Thanks in advance for any assistance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VBA Combo Box

You may want to drop the .listfillrange and .linkedcell and just use code to
populate the combobox and the cell.

I put all this code under the worksheet that held the combobox.

Option Explicit
Private Sub ComboBox1_Change()
With Me.Range("b1")
.NumberFormat = "@" 'text
.Value = Me.ComboBox1.Value
End With
End Sub
Private Sub Worksheet_Activate()
Dim myCell As Range
With Me.ComboBox1
.ListFillRange = ""
.Clear
.Style = fmStyleDropDownList
For Each myCell In Worksheets("sheet2").Range("a1:a10").Cells
.AddItem Format(myCell.Value, "mmm-yy")
Next myCell
End With
End Sub

My "listfillrange" was on Sheet2 in A1:A10.
My "linked" cell was on the same sheet (B1).

Note that by showing mmm-yy, you're losing the date (day of month). That's why
I put the value in as text--not a real date.

And I populated the combobox when the sheet is activated. That may not work for
you. You may want to put that code in the Workbook_Open event (under
ThisWorkbook).

This line:
with me.combobox1
will change to:
with worksheets("sheet1").combobox1



MTinsley wrote:

I normally use a format control drop down box. This is my first time using a
VBA Combo Box. I have two questions that are probably very basic but I can't
get this figured out.

I am using ListFillRange to define a column that has dates. This is
working, however the selection is displayed as a seriel number.

How can I format the display of the user's selection to be in a mmm-yy format?

Also, how do I link a cell to pull the selection from the combo-box?

Thanks in advance for any assistance.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default VBA Combo Box

I have run into this problem before and I will be interested if anyone has a
better answer but here is my workaround:-

Format the dates to text. In VBA it is =Format(yourdate,"dd mmm yyyy")

In the interactive mode on the worksheet it is =TEXT(yourdate,"dd mmm yyyy")

You can use any valid format between the double quotes.

The reverse in VBA to get a date value is Cdate(String)

In the interactivemode VALUE(string)


Regards,

OssieMac


"MTinsley" wrote:

I normally use a format control drop down box. This is my first time using a
VBA Combo Box. I have two questions that are probably very basic but I can't
get this figured out.

I am using ListFillRange to define a column that has dates. This is
working, however the selection is displayed as a seriel number.

How can I format the display of the user's selection to be in a mmm-yy format?

Also, how do I link a cell to pull the selection from the combo-box?

Thanks in advance for any assistance.

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
linking a form combo box... results from the combo box to another Trey Excel Discussion (Misc queries) 1 July 15th 07 01:58 AM
Excel VBA Combo Box Populating dependent on other combo box choices ikabodred Excel Programming 1 March 15th 06 03:16 PM
Filtered list for Combo Box ListFillRange - Nested Combo Boxes DoctorG Excel Programming 3 February 23rd 06 12:15 PM
"Combo Box - getting control combo box to stick in place in worksh ajr Excel Discussion (Misc queries) 1 February 16th 05 02:05 AM
"Combo Box - getting control combo box to stick in place in worksh ajr Excel Discussion (Misc queries) 0 February 15th 05 07:45 PM


All times are GMT +1. The time now is 06:35 AM.

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

About Us

"It's about Microsoft Excel"