Home > Blockchain >  ComboBox doesn't pickup fractions. Why?
ComboBox doesn't pickup fractions. Why?

Time:11-11

I'm not an expert at all on this but I'm trying to create an option list so they can choose either 1/4, 1/2 or 3/4 from the ComboBox for the userform I have created. The Data comes from Sheet1 that perfectly shows the correct format for each value but when you run the form the ComboBox shows instead 0.25, 0.5 or 0.75.

Example

Column A
1/4
1/2
3/4
Private Sub UserForm_Initialize()
    ComboBox1.List = Worksheets("Sheet1").Range("A1:A3").Value
    End Sub

I don't know what to do. I need them to show in fraction format in the simplest way possible. Any ideas how to fix this problem? Thanks

CodePudding user response:

Creating an array and setting the array seems to work for the .text field representation, for a combobox:

Private Sub UserForm_Initialize()
    With Sheets(1)
        Dim textArray As Variant
        ReDim textArray(.Range(.Cells(1, 1), .Cells(3, 1)).Count - 1)
        Dim i As Long
        For i = LBound(textArray) To UBound(textArray)
            textArray(i) = .Cells(i   1, 1).Text
        Next i
    End With
    ComboBox1.List = textArray
End Sub

enter image description here enter image description here

CodePudding user response:

Alternative:

Private Sub UserForm_Initialize()
    With Worksheets("Sheet1")
        ComboBox1.List = .Evaluate("TEXT(A1:A3,""# ?/?"")")
    End With
End Sub
  • Related