Hi experts,
I hope somebody provide me procedure to resize the userform based on add textboxes automatically
the code will add textboxes based on data in sheet . the data in sheet contain four columns so it will add three columns on userform and the rows on userform depends on the last row in sheet.
is there any procedure to add the userform when run it?
should resize the userform by increase or decrease based on how many added textboxes on form?
this is the code
I hope somebody help .
I hope somebody provide me procedure to resize the userform based on add textboxes automatically
the code will add textboxes based on data in sheet . the data in sheet contain four columns so it will add three columns on userform and the rows on userform depends on the last row in sheet.
is there any procedure to add the userform when run it?
should resize the userform by increase or decrease based on how many added textboxes on form?
this is the code
VBA Code:
Option Explicit
Const dateCol = 1
Const invoiceNumCol = 2
Const amountCol = 3
Const paymentCol = 4
Private Sub SaveButton_Click()
Dim row As Range
Dim box As Control
For Each row In ActiveSheet.Rows
On Error GoTo ExitHandler
row.Cells(1, paymentCol).Value = Me.Controls(row.row & paymentCol).Value
Next row
ExitHandler:
Exit Sub
End Sub
Private Sub UserForm_Initialize()
Dim row As Range
For Each row In ActiveSheet.Rows
If row.Cells(1, dateCol).Value = "" Then
Exit For
End If
'End If
Call AddBox(row, dateCol)
Call AddBox(row, invoiceNumCol)
Call AddBox(row, amountCol)
Call AddBox(row, paymentCol)
Next row
End Sub
Private Sub AddBox(row, colIndex)
Dim box As Control
Const width = 50
Const padWidth = width + 4
Const height = 15
Const padHeight = height + 4
Const topMargin = 25
Const leftMargin = 5
Const frmspecialeffectbump = 6
Set box = Me.Controls.Add("Forms.TextBox.1", row.row & colIndex)
box.Left = (colIndex - 1) * padWidth + leftMargin
box.height = height
box.width = width
box.Top = (row.row - 1) * padHeight + topMargin
box.Value = row.Cells(1, colIndex).Value
End Sub