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:
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