format a listbox

G

gem.g

i need to format a listbox as im getting numbers such as 10.875421 and only
want 2 numbers after the decimal e.g. 10.87 can anyone help?
thanks
 
D

Dave Peterson

You may want to share what that listbox is.

Is it on a userform?

Is it a listbox from the Forms toolbar placed on a worksheet?

Is it a listbox from the control toolbox toolbar placed on a worksheet?

I put a listbox from the control toolbox toolbar on a worksheet and used this
code in the worksheet_activate event -- not sure where you would want it to go.

Option Explicit
Private Sub Worksheet_Activate()
Dim myCell As Range
Dim myRng As Range

With Me
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

With Me.ListBox1
For Each myCell In myRng.Cells
.AddItem Format(myCell.Value, "00.00")
Next myCell
End With
End Sub

The important thing was the .additem stuff and the format statement.
 
Top