minimize and maximize the userform based on values showing in textboxes

Ali M

Active Member
Joined
Oct 10, 2021
Messages
290
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
 
If you're wanting to have a smaller Userform but have a lot of controls, have you tried using a Multipage on your userform. Look in the Toolbox for multipage.
Then only put the controls you need on each Multipage Page
So, on Project1 put just the controls you need for that multipage page
A Multipage is sort of like a workbook with numerous sheets
The controls you always need to see put them on the userform but not on the Multipage Page
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
@dmt32 this is my code

VBA Code:
Private Sub UserForm_Initialize()

Dim i As Long, lastrow As Long, ws As Worksheet
Set ws = Sheets("DATA")
lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lastrow
If ws.Cells(i, "c") < 0 Then
TextBox1.Value = Range("a" & i).Value
TextBox2.Value = Range("b" & i).Value
TextBox3.Value = Range("c" & i).Value
TextBox4.Value = Range("a" & i).Value
TextBox5.Value = Range("b" & i).Value
TextBox6.Value = Range("c" & i).Value
TextBox7.Value = Range("a" & i).Value
TextBox8.Value = Range("b" & i).Value
TextBox9.Value = Range("c" & i).Value
TextBox10.Value = Range("a" & i).Value
TextBox11.Value = Range("b" & i).Value
TextBox12.Value = Range("c" & i).Value
End If
Next
End Sub
 
Upvote 0
@EXCEL MAX thanks , but it just hide empty textboxes .it left spaces for empty textboxes has been hidden .without decrease the form size by move to up or move to the bottom based on filled textboxes .
 
Upvote 0
sorry Dave ! you'r right should be 15 textboxes . I was in hurry .
 
Upvote 0
sorry Dave ! you'r right should be 15 textboxes . I was in hurry .

can you post your complete code (you have each row of textboxes accessing the same ranges - is this correct?) & sample data if possible

Dave
 
Upvote 0
(you have each row of textboxes accessing the same ranges - is this correct?)
surely wrong , I will find way to fix it .
the data in sheet
CAKL.xlsm
ABC
1ITEMCODEQTY
21CLA12-100.00
32MS-11200.00
43CLA13-200.00
54MS-13200.00
65MS-14200.00
76MS-15200.00
87MS-16200.00
98MS-17200.00
109MS-18-200.00
1110MS-19200.00
1211MS-20-100.00
1312MS-21-200.00
DATA



the userform when run it should be like this based on condition in sheet DATA
5.PNG


the whole code
VBA Code:
Private Sub UserForm_Initialize()

Dim i As Long, lastrow As Long, ws As Worksheet
Set ws = Sheets("DATA")
lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lastrow
If ws.Cells(i, "c") < 0 Then
TextBox1.Value = Range("a" & i).Value
TextBox2.Value = Range("b" & i).Value
TextBox3.Value = Range("c" & i).Value
TextBox4.Value = Range("a" & i).Value
TextBox5.Value = Range("b" & i).Value
TextBox6.Value = Range("c" & i).Value
TextBox7.Value = Range("a" & i).Value
TextBox8.Value = Range("b" & i).Value
TextBox9.Value = Range("c" & i).Value
TextBox10.Value = Range("a" & i).Value
TextBox11.Value = Range("b" & i).Value
TextBox12.Value = Range("c" & i).Value
TextBox13.Value = Range("a" & i).Value
TextBox14.Value = Range("b" & i).Value
TextBox15.Value = Range("c" & i).Value

End If
Next
End Sub
 
Upvote 0
Form new image I see textboxes are not aligned on the top.
My code Is based on same textbox "Top" property in Each line.
Suppose you should need to take care is it each three textboxes
on the same "Top" property and make the same distance between each line with textboxes.
Align textboxes carefully and properly and try code again.
 
Upvote 0
@EXCEL MAX for clarification the new picture for my orginal code how works as Dave ask me for
you have each row of textboxes accessing the same ranges - is this correct?
about your guiding me I will test it again and come back soon
 
Upvote 0
surely wrong , I will find way to fix it .

Have you placed the TextBoxes In a Frame named Frame1 & the CommandButtons in a Frame named Frame2 as shown in #post 7?

Dave
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,685
Members
449,463
Latest member
Jojomen56

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