View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
JustLearning JustLearning is offline
external usenet poster
 
Posts: 16
Default Spacing in a listbox

Yes that works!! But still have a small problem my userform gives me an
object variable or with variable not set error with the new code after it
ran?(When trying to close the form, I am using unload userform2)
And why if I use a different font it gets all messy again?

"Chip Pearson" wrote:

If you can live with a fixed-width font such as Courier New in the listbox,
you can use the SizeString function on www.cpearson.com/excel/SizeString.htm
to create substrings of a specific number of characters, padded on the left
or right with space characters (or any character you want) or truncated on
the right to fill the specified number of characters.

Sub AAA()
Dim S As String
Dim Rng As Range
UserForm1.ListBox1.Font.Name = "Courier New"
UserForm1.ListBox1.Clear
For Each Rng In Range("A1:A3")
S = SizeString(Text:=Rng(1, 1).Text, Length:=20, _
TextSide:=TextLeft, PadChar:=" ") & _
SizeString(Text:=Rng(1, 2), Length:=20, _
TextSide:=TextLeft, PadChar:=" ") & _
SizeString(Text:=Rng(1, 3), Length:=20, _
TextSide:=TextLeft, PadChar:=" ")
UserForm1.ListBox1.AddItem S
Next Rng
UserForm1.Show
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)




"JustLearning" wrote in message
...
It works but still it does not solve the problem:
I have found that if I use a word smaller than 8 characters and a word
longer than 13 characters this happens:

St Annes 2007/02/17
St Augustine 2007/02/17

But if i count the char and use an if statement that states if the char <
8
then using two vbtabs or else only one vbtab then i get

St Annes 2007/02/17
St Augustine 2007/02/17
But this if statement effects the 3,4,5 columns and messes the columns up
again


"Bob Phillips" wrote:

With Me.ListBox1
For Each c In Range("A1:A10")
For i = 0 To 2
tmp = tmp & c.Offset(0, i).Value & vbTab
Next i
.AddItem tmp
Next c
End With


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"JustLearning" wrote in message
...
I have a listbox which I ad data to with listbox.additem "" &
c.offset(0,-1)
& ......
But some cells has longer names in them and thus I cannot seem to list
them
neatly next to each other for example:

Appels 1000 Bear
Apricot-jam 30 Impala

How can i get the spacing correct?

Any help will do
Thanks