Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format ListBox Columns

Status
Not open for further replies.

jpgactmod

Technical User
Feb 12, 2004
41
US
I have used the "FormatNumber" VBA function to format Column 1 in a ListBox for numbers with four decimal points:
Area(1, j) = FormatNumber(Range(“A1”), 4)
If I wanted a different format for column 2 (e.g. six decimal points) this can easily be done with:
Area(2, j) = FormatNumber(Range(“A1”), 6)
My question is whether a comparable VBA format function exists to format text to be either left, center, or right justified for different columns. So far I have only been able to use the same formatting for text for all columns.

Any suggestions? Thanks much.
 
A listbox control only stores TEXT.

Use the Format() function to convert your number to text and assign whatever number of decimal places you like.
Code:
X=format(YourNum, "#,###.000")

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thank you but I am not trying to format a number. I am trying to format Text. Specifically, I currently have the "TextAlign" "Properties" for the ListBox set to "2-fmTextAlignCenter". I am trying to get one column in the ListBox left-aligned (i.e. effectively set to "1-fmTextAlignLeft") while leaving the other columns centered. I am beginning to think that this is not possible - at least not for someone with my limited skills. Thanks again for your help.
 
You could always set the listbox to use a fixed width font and pad the entries with spaces to the right so that the length of all entries were the same.

That is, of course, a very sloppy way of doing things. I don't recommend doing it that way if you can avoid it. You might have real issues if you need to process the selection text. (though I suppose you could just trim it.)
 
Thank you for the suggestion. Yes, I have been doing some pretty sloppy fixes myself:). Specifically, iteratively playing with the number of spaces between the columns and manually moving column headings above the ListBox. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top