Gap between 65 textboxes and labels is huge. Require the perfect gap between eachother

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
688
Hello

What i want is to display 65 textboxes and 65 labels adjacent to each other in 3 or 5 columnar way on the userform at run time.

Textbox and Label Top Position starts from 144

so when used the following in below code for both controls textbox and label .Top = 144 * i * 1 the gap between each Label and Textbox is huge and looks bad.
How can i get the perfect gap between each label and Textbox respectively below each other and also perfect gap for columnar representation on userform.

Label TextBox Label TextBox Label TextBox
Label TextBox Label TextBox Label TextBox
Label TextBox Label TextBox Label TextBox
Label TextBox Label TextBox Label TextBox
Label TextBox Label TextBox Label TextBox
Label TextBox Label TextBox Label TextBox
Label TextBox Label TextBox Label TextBox
Label TextBox Label TextBox Label TextBox
Label TextBox Label TextBox Label TextBox
Label TextBox Label TextBox Label TextBox
......so on


Code:
Private Sub UserForm_Initialize()
Dim i As Integer
Dim txtbxTopPos As Integer
Dim txtbxGap As Integer


Dim txtB1 As Control
Dim labl As Control


For i = 1 To 65
Set txtB1 = Controls.Add("Forms.TextBox.1")
Set labl = Controls.Add("Forms.Label.1")
With txtB1
.Name = "txtBox" & i
.Height = 15.75 
.Width = 126    
.Left = 102     
.Top = 144 * i * 1
End With


With labl
.Name = "lbl" & i
.Height = 15.75 
.Width = 126    
.Left = 10     
.Top = 144 * i * 1
.BackStyle = 0
.Caption = Sheet1.Cells(1, i).Value
End With

Next i
End Sub

Thankx NimishK
 
Last edited:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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