minimize and maximize the userform based on values showing in textboxes

Ali M

Active Member
Joined
Oct 10, 2021
Messages
287
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hi experts,
I want minimizing and maximizing the userform based on values showing in tools . just show the textboxes on userform contains values when run the userform and ignore textboxes are empty


this is what I got when run the userform
1.PNG



what I want if each three textboxes are empty shouldn't show like this

2.PNG

note: if one or two of for each three textboxes contains value then shouldn't show.

thanks
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
@EXCEL MAX you're right but just in textboxes , why creates spaces under commandbuttons and how implement your code based on the code populates in textboxes
how replace of this line?
VBA Code:
 TextBox4 = "TextBox4": TextBox5 = "TextBox5": TextBox6 = "TextBox6"
   TextBox10 = "TextBox10": TextBox11 = "TextBox11": TextBox12 = "TextBox12"
1.PNG


2.PNG
 
Upvote 0
Vertically space between textboxes also need to be same, because code works in that way.
The code makes invisible more rows and to resize userform height,
its not enough to calculate only height of the invisible textbox, but vertically space between textboxes also.
In the original post there was nothing about filling textboxes.
We were suppose that you have data in the textboxes.
 
Upvote 0
@dmt32 yes I will do that .

some very light testing I have these results from your data

1653327898291.png


if I change some of the values positive form now displays like this

1653328086647.png


can you confirm this is the result you are looking for?

Dave
 
Upvote 0
@EXCEL MAX
Vertically space between textboxes also need to be same, because code works in that way.
but I don't think to be Vertically different space between textboxes based on the pictures . the problem is commandbuttons below as in pic2

In the original post there was nothing about filling textboxes.
the values in textboxes brings by another code , my question is how can I call my macro to brings values into text boxes before running your code . where put it inside your code?
 
Upvote 0
If you have macro to populate textboxes it's great.
Call that macro below "fill your data" comment
and don't forget to delete my example filling textboxes (4,5,6,10,11,12).
If you have more textboxes on the userform you need to tell me that.
 
Last edited:
Upvote 0
If you have more textboxes on the userform you need to tell me that.
currently no , but in the future this possibilty can be , if you have idea about it how deal with more textboxes will be good.
 
Upvote 0
@dmt32 yes it will be great if you can achieve it
Hi,

To clarify, its important that your Userform is configured like this

1653334484661.png


The textboxes are placed in a Frame named Frame1

The Texboxes have their default names & are configured

TextBox1 TextBox2 TextBox3

TextBox4 TextBox5 TextBox6


Etc.

The CommandButtons are Placed in a Frame named Frame2

Providing this is the case then
  • Make backup of your workbook
  • delete any previous code you have for this requirement
  • place following code in the userform code page
Code:
Public BoxSpace As Double, BoxHeight As Double, BoxWidth As Double
Dim ws          As Worksheet

Private Sub UserForm_Activate()
     DisplayTextBoxes Me
End Sub

Private Sub UserForm_Initialize()
    
    'get textbox height, width & spacing
    With Me.TextBox1
        BoxHeight = .Height
        BoxWidth = .Width
        BoxSpace = Me.TextBox4.Top - .Top - BoxHeight
    End With

    Set ws = ThisWorkbook.Worksheets("DATA")
    
    ConfigureForm Me
    
    GetRecord Me, ws
    
End Sub

Note the variables sitting at the TOP – These MUST sit at very TOP of your forms code page OUTSIDE any procedure

  • insert 3 standard modules & name them as follows
  • ConfigureForm_Code
  • DisplayTextBoxes_Code
  • GetRecord_Code
And let me know when this has been done.



Dave
 
Upvote 0
Exclude that text boxes when you collecting other in the array.
Do you see difference?
VBA Code:
'separate textboxes
   For Each vCtrl In Controls
      If TypeName(vCtrl) = "TextBox" And _
         Not vCtrl.Name = "TextBox16" And _
         Not vCtrl.Name = "TextBox17" And _
         Not vCtrl.Name = "TextBox18" Then
         vAT = vAT & Controls(vCtrl.Name).Name & " "
      End If
   Next vCtrl
   vAT = Split(Trim(vAT), " ")
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,520
Members
449,088
Latest member
RandomExceller01

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