Auto Size/Adjust Userform

Richard Baluyut

I'm new with VBA Programming, I have a Userform with TextBoxes,Labels, and Checkboxes.

My problem is how to Auto size or adjust the form, Because I have hidden Textbox and Label, Now if I click the Button it will unhide the Texbox and Label and also it will auto size the Form and the other controls.

I don't know how to start this.

Actual Result

enter image description here

Let's assume there is hidden Label and Texbox between Team Name and Last Name now I click the update RadioButton it will unhide the hidden Label and Texbox and adjust the form and other controls.

Expected Result

enter image description here

Is there any way to do this?

Variatus

Say, the space required by the control Tbx hidden at the level 90pt from the top is 30pt. Therefore all controls below it should be moved down by 30pt when Tbx is made visible, and the form's height also increased by that same measure. The code below would accomplish that while at the same time unhiding the control.

Dim Ctl As MSForms.Controls

For Each Ctl In Me.Controls
    With Ctl
        If .Top >= 90 Then
            If .Visible = True Then
                .Top = Top + 30
            Else
                .Visible = True
            End If
        End If
    End With
Next Ctl
Me.Top = Top + 30

Two things would be different in practice.

  1. You may have to hide the control again.
  2. Your would create the control on the fly rather than keep it hidden.

If you plan on hiding the control again you would need an array of all affected control names and another array (or dimension) for their existing Tops. You would loop through all the names in the array and reset the top, like,

Me.Controls(Arr(0, i)).Top = Arr(1, i) + Iif(HideMe, 0, 30)

Look into creating the control on the fly. You should be able to simply create a copy of an existing control from which it inherits all properties. Any event code for that control needs to be prepared in advance, however.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

UserForm ComboBox

分類Dev

Update a userform listbox after userform initialization

分類Dev

VBA UserForm label in spreadsheet

分類Dev

Conflict bewteen OLEObjects and Userform

分類Dev

Put variable in UserForm name

分類Dev

sql source for a vba userform

分類Dev

Self Adjusting Userform Size

分類Dev

Userform not copying data to spreadsheet

分類Dev

Move value from one UserForm to another (variable) UserForm

分類Dev

Userform listbox that depends on another listbox

分類Dev

Userform QueryClose Will only Work Once

分類Dev

VBA - destroy a modeless UserForm instance properly

分類Dev

Is it possible to create and handle a custom Event in a Customized UserForm?

分類Dev

Userform Timestamp Cell When textbox Update

分類Dev

How to pass a property as an argument for userform controls?

分類Dev

Excel VBA UserForm printscreen save as pdf

分類Dev

Chosen result from Worksheet cell to Userform Combobox

分類Dev

Delete a selected row from list boxes in Userform

分類Dev

Use content of cell as text for label in UserForm

分類Dev

Vba UserForm combobox items don't apear till i click on the userform

分類Dev

UserForm変数スコープ:userform2からuserform1に2D配列値を転送します

分類Dev

VBA Entering userform data at next blank row correctly

分類Dev

Excel VBA Userform Listbox Dynamic Context Menu Using .OnAction Method

分類Dev

TextBox / Userformの日付値の比較

分類Dev

Using sql recordset to determine which userform is shown on loading

分類Dev

Double click event in the excel sheet column to fill all textboxes of a Userform

分類Dev

How to maintain cursor position when enforcing Change() on a UserForm TextBox?

分類Dev

How to create a Login in userform with 2 or 3 Username and Password?

分類Dev

How do I call a module from my userform in vba?

Related 関連記事

  1. 1

    UserForm ComboBox

  2. 2

    Update a userform listbox after userform initialization

  3. 3

    VBA UserForm label in spreadsheet

  4. 4

    Conflict bewteen OLEObjects and Userform

  5. 5

    Put variable in UserForm name

  6. 6

    sql source for a vba userform

  7. 7

    Self Adjusting Userform Size

  8. 8

    Userform not copying data to spreadsheet

  9. 9

    Move value from one UserForm to another (variable) UserForm

  10. 10

    Userform listbox that depends on another listbox

  11. 11

    Userform QueryClose Will only Work Once

  12. 12

    VBA - destroy a modeless UserForm instance properly

  13. 13

    Is it possible to create and handle a custom Event in a Customized UserForm?

  14. 14

    Userform Timestamp Cell When textbox Update

  15. 15

    How to pass a property as an argument for userform controls?

  16. 16

    Excel VBA UserForm printscreen save as pdf

  17. 17

    Chosen result from Worksheet cell to Userform Combobox

  18. 18

    Delete a selected row from list boxes in Userform

  19. 19

    Use content of cell as text for label in UserForm

  20. 20

    Vba UserForm combobox items don't apear till i click on the userform

  21. 21

    UserForm変数スコープ:userform2からuserform1に2D配列値を転送します

  22. 22

    VBA Entering userform data at next blank row correctly

  23. 23

    Excel VBA Userform Listbox Dynamic Context Menu Using .OnAction Method

  24. 24

    TextBox / Userformの日付値の比較

  25. 25

    Using sql recordset to determine which userform is shown on loading

  26. 26

    Double click event in the excel sheet column to fill all textboxes of a Userform

  27. 27

    How to maintain cursor position when enforcing Change() on a UserForm TextBox?

  28. 28

    How to create a Login in userform with 2 or 3 Username and Password?

  29. 29

    How do I call a module from my userform in vba?

ホットタグ

アーカイブ