Format specific columns in listbox

Bandito1

Board Regular
Joined
Oct 18, 2018
Messages
239
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I got this code that fills my listbox;

VBA Code:
Option Explicit
Dim Ary As Variant

Private Sub UserForm_Initialize()
   Ary = Sheets("BMR data").Range("A3", Sheets("BMR data").Range("A" & Rows.Count).End(xlUp).Offset(, 22)).Value
   With Me.lstSearchResults
      .ColumnCount = 22
      .ColumnWidths = "0;100;0;0;0;0;0;0;0;100;0;0;100;0;0;100;0;0;100;0;0;1"
      .List = Ary
   End With
End Sub

In some column are dates (for example column B)
That column shows the date in the listbox as 14-3-2023.
Can i format that specific column to dd/mmm/yy ?

In some columns are percentages (columns J, M, P, S, V)
Those percentages are displayed as 0.874949494.
Can i format a specific column so it displays 87%?

Generic question; how can i format a specific column in my code?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
A Listbox shows "text", so you have to convert the info according their meaning before loading the control. For example:
VBA Code:
Private Sub UserForm_Initialize()
   Ary = Sheets("BMR data").Range("A3", Sheets("BMR data").Range("A" & Rows.Count).End(xlUp).Offset(, 22)).Value
'Format conversion:
   For I = 1 To UBound(Ary)
        Ary(I, 15) = Format(Ary(I, 15), "dd-mmm-yyyy")      'Date
        Ary(I, 22) = Format(Ary(I, 22), "0.0%")             '%
   Next I
   With Me.lstSearchResults
'etc
'etc
This way I converted a date in column 15 and a percentage in column 22
 
Upvote 0
Solution

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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