List Column Decimal Format

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,280
Office Version
  1. 2013
Platform
  1. Windows
Code:
Private Sub CommandButton9_Click()
Dim r As Range, vAr1 As Variant, vAr2 As Variant
Dim cnt As Long, i As Long, j As Long, lngCritColumn As Long
Dim arrCrit As Variant
arrCrit = Array("AREA 1", "AREA 2", "AREA 3", "AREA 4", "AREA 5")
ListBox1.Clear
With Worksheets("halls")
Set r = .Range("i1:k" & .Cells(.Rows.Count, "i").End(xlUp).Row)
End With
lngCritColumn = 1
vAr1 = r.Value
cnt = Application.Sum(Application.CountIf(r.Columns(lngCritColumn), arrCrit))
If cnt > 0 Then
ReDim vAr2(1 To cnt, 1 To UBound(vAr1, 2))
cnt = 0
For i = 1 To UBound(vAr1, 1)
If IsNumeric(Application.Match(vAr1(i, lngCritColumn), arrCrit, 0)) Then
cnt = cnt + 1
For j = 1 To UBound(vAr1, 2)
vAr2(cnt, j) = vAr1(i, j)
Next
End If
Next
Me.ListBox1.List = vAr2
End If
With ListBox1
.ColumnCount = 3
.ColumnWidths = "80;80;60"
End With
End Sub


Good Day,
How can we format the column 3 values like ...?
Code:
.NumberFormat = "#,##0.000"
Many Thanks
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You have to format each value one at a time. Try something like this...
Code:
Private Sub CommandButton9_Click()
Dim r As Range, vAr1 As Variant, vAr2 As Variant
Dim cnt As Long, i As Long, j As Long, lngCritColumn As Long
Dim arrCrit As Variant
arrCrit = Array("AREA 1", "AREA 2", "AREA 3", "AREA 4", "AREA 5")
ListBox1.Clear
With Worksheets("halls")
Set r = .Range("i1:k" & .Cells(.Rows.Count, "i").End(xlUp).Row)
End With
lngCritColumn = 1
vAr1 = r.Value
cnt = Application.Sum(Application.CountIf(r.Columns(lngCritColumn), arrCrit))
If cnt > 0 Then
ReDim vAr2(1 To cnt, 1 To UBound(vAr1, 2))
cnt = 0
For i = 1 To UBound(vAr1, 1)
If IsNumeric(Application.Match(vAr1(i, lngCritColumn), arrCrit, 0)) Then
cnt = cnt + 1
For j = 1 To UBound(vAr1, 2)
vAr2(cnt, j) = vAr1(i, j)
Next
[COLOR="Red"]vAr2(cnt, 3) = Format(vAr2(cnt, 3), "#,##0.000")[/COLOR]
End If
Next
Me.ListBox1.List = vAr2
End If
With ListBox1
.ColumnCount = 3
.ColumnWidths = "80;80;60"
End With
End Sub
 
Upvote 0
You have to format each value one at a time. Try something like this...
Code:
Private Sub CommandButton9_Click()
Dim r As Range, vAr1 As Variant, vAr2 As Variant
Dim cnt As Long, i As Long, j As Long, lngCritColumn As Long
Dim arrCrit As Variant
arrCrit = Array("AREA 1", "AREA 2", "AREA 3", "AREA 4", "AREA 5")
ListBox1.Clear
With Worksheets("halls")
Set r = .Range("i1:k" & .Cells(.Rows.Count, "i").End(xlUp).Row)
End With
lngCritColumn = 1
vAr1 = r.Value
cnt = Application.Sum(Application.CountIf(r.Columns(lngCritColumn), arrCrit))
If cnt > 0 Then
ReDim vAr2(1 To cnt, 1 To UBound(vAr1, 2))
cnt = 0
For i = 1 To UBound(vAr1, 1)
If IsNumeric(Application.Match(vAr1(i, lngCritColumn), arrCrit, 0)) Then
cnt = cnt + 1
For j = 1 To UBound(vAr1, 2)
vAr2(cnt, j) = vAr1(i, j)
Next
[COLOR=red]vAr2(cnt, 3) = Format(vAr2(cnt, 3), "#,##0.000")[/COLOR]
End If
Next
Me.ListBox1.List = vAr2
End If
With ListBox1
.ColumnCount = 3
.ColumnWidths = "80;80;60"
End With
End Sub


Many Thanks
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,677
Members
449,092
Latest member
tayo4dgacorbanget

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