Formatting data in a ListBox

phil-007

New Member
Joined
May 14, 2013
Messages
32
Hello all,

I have a listbox attached to a userform to display data from another sheet, However the listbox displays the data as text only and my data is a combination of text, numbers, currency & percentages.

Could somebody advise what VBA I need to insert to re-format the data into the appropriate formats please? I'm a newbie at VBA so apologies if it's a daft question

Current vba is:

Code:
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
 
'set filter on alternatives tab to current NPC
Dim code As String
Dim code2 As String

    Selection.Copy
    Sheets("countrow").Select
    Range("C1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   code = Range("npcfilter").Value
  Sheets("Alternatives").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=2, Criteria1:= _
    code

      ActiveSheet.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(1, 2).Select
       Sheets("matched products").Select
'coppies alternate products to listbox1 tab to be displayed on form
Call copy_alt_products

'Show list of other alternate products
Dim lbtarget As MSForms.ListBox
    Dim rngSource As Range
    
    'Set reference to the range of data to be filled
    Set rngSource = Worksheets("listbox1").Range("a1:zz999")
    
    'Fill the listbox
    Set lbtarget = Me.ListBox1
    With lbtarget
        'Determine number of columns
        .ColumnCount = 30
        For lngIndex = 0 To .ListCount - 1
    .List(lngIndex, 16) = (Format(Val(.List(lngIndex, 16)), "$#,##0.00"))
Next
        'Set column widths
        .ColumnWidths = "0.01;0;0;0;0;0;0;0;0;50;150;75;0;55;40;0;65;0;45;0;85;85;100;100;0;0;0;65;0;0"
        'Insert the range of data supplied
 
      
        .List = rngSource.Cells.Value
    End With
end sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top