centering text on textbox

  • Thread starter Thread starter Alberto Ast
  • Start date Start date
A

Alberto Ast

I have a userform just to display some info. In the form I have a textbox
where I pull lots of info including some vbtab and vbcr.

is there a way to center some of the lines texts
I would like to put some titles in the middle but center in the textbox.

my program looks like this

Private Sub UserForm_Initialize()
Me.TextBox1 = _
"Model:" & vbTab & vbTab & vbTab & Range("o12").Value & vbCr _
& "Customer: " & vbTab & vbTab & Range("n26").Value & vbCr _
& "Qty:" & vbTab & vbTab & vbTab & Range("J26").Value & vbCr & vbCr _
& "Part Description: " & vbTab & Range("O17").Value & vbCr _
& "Original P/N: " & vbTab & vbTab & Range("O14").Value & vbCr _
& "Replacement P/N: " & vbTab & Range("O20").Value & vbCr _
& "ECR Requested: " & vbTab & Range("F12").Value & vbCr & vbCr _
& "Description: " & Range("A30").Value & vbCr & vbCr _
& "Prevention: " & Range("A38").Value & vbCr & vbCr
End Sub
 
Why don't you just put 9 Textboxes and 9 Labels on your userform? Then at
design time you can change the Caption property to "Model", "Customer", etc.
It would save you a lot of headches trying to center and format stuff. Hope
this helps! If so, let me know, click "YES" below.

Private Sub UserForm_Initialize()

Me.TextBox1 = Range("O12").Value
Me.TextBox2 = Range("N26").Value
Me.TextBox3 = Range("J26").Value
Me.TextBox4 = Range("O17").Value
Me.TextBox5 = Range("O14").Value
Me.TextBox6 = Range("O20").Value
Me.TextBox7 = Range("F12").Value
Me.TextBox8 = Range("A30").Value
Me.TextBox9 = Range("A38").Value

End Sub
 
A little more compact code...

Private Sub UserForm_Initialize()
Dim X As Long, Addresses() As String
Addresses = Split("O12 , N26, J26,O17,O14,O20, F12,A30,A38", ",")
For X = 1 To UBound(Addresses) + 1
Controls("TextBox" & X).Value = Range(Trim(Addresses(X - 1))).Value
Next
End Sub

This is also quite flexible in that if more TextBoxes are added or deleted, the only thing that needs to be changed is the list of addresses in the first argument to the Split function.
 
I meant to leave the spaces out of the list of addresses... they don't affect anything if left in (since I'm using the Trim function call) but they don't look all that nice.

--
Rick (MVP - Excel)


A little more compact code...

Private Sub UserForm_Initialize()
Dim X As Long, Addresses() As String
Addresses = Split("O12 , N26, J26,O17,O14,O20, F12,A30,A38", ",")
For X = 1 To UBound(Addresses) + 1
Controls("TextBox" & X).Value = Range(Trim(Addresses(X - 1))).Value
Next
End Sub

This is also quite flexible in that if more TextBoxes are added or deleted, the only thing that needs to be changed is the list of addresses in the first argument to the Split function.
 
Thanks for all the inputs...

I do not think I can use several textbpxes or labels because the lenght of
each item can vary a lot so I will need to have space enough for each item
rather than just one are with all data... it will not look good.

I will try joel options, did acess such option and there are too many pcs of
information... do not think it will work but I will try... most chances is it
should work because my experience is very low on this so I should be wrong.
 
Back
Top