format number(#,##0.00) & date(yyyy/mm/dd) doesn't work in listbox on userfrom

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hello
I have this part of my project
Rich (BB code):
Private Sub LBoxPop()
  Data = ws.Cells(1).CurrentRegion.Value: x = 0
  ReDim Temp(1 To UBound(Data, 1), 1 To 5)
  For i = 1 To UBound(Data)
      x = x + 1
      Temp(x, 1) = Format(Data(x, 1), "yyyy/mm/dd")
       Temp(x, 3) = Format(Data(x, 3), "#,##0.00")
       Temp(x, 4) = Format(Data(x, 4), "#,##0.00")
       Temp(x, 5) = Format(Data(x, 5), "#,##0.00")
      For ii = 1 To 5
        Temp(x, ii) = Data(i, ii)
      Next ii
    'End If
  Next i
  With UserForm1.ListBox1
    .ColumnCount = 5
    .columnWidths = "80;240;120;120;120"
    .List = Temp
  End With
End Sub
I try showing format date in first column in listbox like this 2023/08/06
and formatnumber in column 3,4,5 like this 200,220.00
but doesn't work for me as in code above and bold lines
any help to fix it ,please ?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi,
assuming that the ranges in your worksheet are displaying the required formats then see if this update to your code does what you want

VBA Code:
Private Sub LBoxPop()
    Dim r          As Long, c As Long
    Dim Data()     As Variant
    Dim rng        As Range
  
    Set rng = ws.Cells(1, 1).CurrentRegion
    ReDim Data(1 To rng.Rows.Count, 1 To rng.Columns.Count)
   
    For r = 1 To UBound(Data, xlRows)
        For c = 1 To UBound(Data, xlColumns)
            Data(r, c) = rng.Cells(r, c).Text
        Next c
    Next r
   
    With UserForm1.ListBox1
        .ColumnCount = 5
        .columnWidths = "80;240;120;120;120"
        .List = Data
    End With
   
End Sub

I am also assuming that your object variable ws has been intialized elsewhere in your project.

Dave
 
Upvote 0
Solution
Hello
I have this part of my project
Rich (BB code):
Private Sub LBoxPop()
  Data = ws.Cells(1).CurrentRegion.Value: x = 0
  ReDim Temp(1 To UBound(Data, 1), 1 To 5)
  For i = 1 To UBound(Data)
      x = x + 1
      Temp(x, 1) = Format(Data(x, 1), "yyyy/mm/dd")
       Temp(x, 3) = Format(Data(x, 3), "#,##0.00")
       Temp(x, 4) = Format(Data(x, 4), "#,##0.00")
       Temp(x, 5) = Format(Data(x, 5), "#,##0.00")
      For ii = 1 To 5
        Temp(x, ii) = Data(i, ii)
      Next ii
    'End If
  Next i
  With UserForm1.ListBox1
    .ColumnCount = 5
    .columnWidths = "80;240;120;120;120"
    .List = Temp
  End With
End Sub
I try showing format date in first column in listbox like this 2023/08/06
and formatnumber in column 3,4,5 like this 200,220.00
but doesn't work for me as in code above and bold lines
any help to fix it ,please ?
Try using the .AddItem method. It worked for me recently.
 
Upvote 0
I am also assuming that your object variable ws has been intialized elsewhere in your project.
yes that's correct
your new version works perfectly .(y)
thank you so much , Dave .:)
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,035
Members
449,092
Latest member
ikke

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