Excel combo box

B

bobeverton

Is there an easy way to maintain a date format from the original cell
through selection via a combo box?
 
D

Dave Peterson

If you add the items yourself--instead of using listfillrange, then the combobox
from the control toolbox toolbar will keep the formatting:

Option Explicit
Private Sub Worksheet_Activate()
Dim myCell As Range
With Me.ComboBox1
.ListFillRange = ""
.Clear
For Each myCell In Me.Range("a1:a14").Cells
.AddItem myCell.Text
Next myCell
End With
End Sub

or if you wanted to just use your own format, you could format it whenever it
changed:

Option Explicit
Dim blkProc As Boolean
Private Sub ComboBox1_Change()

If blkProc Then Exit Sub
blkProc = True
Me.ComboBox1.Value = Format(Me.ComboBox1.Value, "mm/dd/yyyy")
blkProc = False

End Sub

====
I put both of these functions behind the worksheet that held the combobox.

I don't think you'd want to use both!
 

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

Top