Solved

How to Dynamically Change the Size of a Frame and Scrollbar on an Excel UserForm

Posted on 2014-12-16
17
1,054 Views
Last Modified: 2014-12-16
I have a list of names on a spreadsheet that I am dynamically adding to a UserForm.  The list is variable resulting in the need to dynamically build the list.  The names are contained within a frame on the UserForm.

How can I adjust the size of the frame and scrollbar based on the number of names placed on the form?
I thought I could simply change the frame height and scrollbar height as the names were being placed on the form but this apparently does not work. (See attached)

Any help that you can provide would be greatly appreciated.

Thank you.
Sample-Dynamic-Frame-and-Scrollbar-v1.1.
0
Comment
Question by:Quiver
  • 8
  • 7
  • 2
17 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40502462
You can change the height etc.

For example:

UserForm_search.Frame1.Height = 500

reduces the height significantly.
0
 

Author Comment

by:Quiver
ID: 40502568
I thought I was varying the height dynamically with the following code where iCntrlList is incremented with each name line that is added to the UserForm.  But apparently this is not changing the height of the frame and scrollbar.  Any other suggestions?

    With UserForm_Search.Frame1
       .ScrollHeight = Frame_Scroll_Height + (Search_intHeight + Search_intVerticalGap) * iCntrList
       .Height = Frame_Height + (Search_intHeight + Search_intVerticalGap) * iCntrList
    End With
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40502866
It may be changing it, but the calculation may not be correct.

My experiment to change it resulted in it being - not quite right.

As an experiment, try putting /3 at the end of each line.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Quiver
ID: 40502970
/3 results in less names being displayed.

As currently coded, 22 of the 63 names are displayed.  The Scroll height increments to 1446 and the Height increments to 1046 while displaying the results.  When the Scroll height increments to 1489 and the Height increments to 1089 the results are no longer displayed.  I have attached some snagits from the displays that I put in.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40503003
I'd like to try to help but I have no idea how to deal with the XML. I have a question though and that is why are you you using a frame and scrollbar and not a Listbox or Listview control?
0
 

Author Comment

by:Quiver
ID: 40503234
It's not XML.  It is VBA.  This is one of many userforms, some with multiple pages, etc.  There is some static data on some of the forms that resulted in the frame being the best solution.  On many of the userforms/pages, the data is dynamically added but I know the maximum length of the frame.  

With this particular userform, I do not know the maximum length of the frame/scrollbars.  It is totally dependant on the number of rows of names (which is variable).

Thanks for your offer to help though.  Any and all help is appreciated.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40503257
It's not XML.  It is VBA.  
Here's what I see when I unpack your zip file.
XML?But in any case I ask again why are you using a frame rather then a listbox or listview, both of which are designed for dynamic data?
0
 

Author Comment

by:Quiver
ID: 40503656
Hopefully, the file is now uploaded as a .xlsm file.  Sorry about that.  Unfortunately, it needs to be a frame to be consistent with the rest of the application.
Sample-Dynamic-Frame-and-Scrollbar-v1.1.
0
 

Author Comment

by:Quiver
ID: 40503684
Just realized that I cannot name a file with a dot (.) when uploading.  Hopefully, the file is now being uploaded as a .xlsm file.
Sample-Dynamic-Frame-and-Scrollbar-v1-1.
0
 

Author Comment

by:Quiver
ID: 40503688
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40503693
Sorry to say but the zip still looks the same. How are you creating the zip file? What version of Excel are you using?
0
 

Author Comment

by:Quiver
ID: 40503701
Let's try again
Sample.xlsm
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40503778
OK now we're getting somewhere. Be back soon.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40503806
I don't understand something and that is why do you want to change the height of the frame? Since you have a scrollbar it would seem to me that you shouldn't need to do that.
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40503812
I just comment out this code in UserForm_Initialize and it seems to work correctly.
    With UserForm_Search.Frame1
       .ScrollHeight = Frame_Scroll_Height + (Search_intHeight + Search_intVerticalGap) * iCntrList
       .Height = Frame_Height + (Search_intHeight + Search_intVerticalGap) * iCntrList
      '  MsgBox ("ScrollHeight " & .ScrollHeight & " Height " & .Height)
    End With

Open in new window


Try it and tell me if you disagree.
0
 

Author Closing Comment

by:Quiver
ID: 40503967
Actually, after you questioned why I was changing the height of the frame, I commented out the height in the code above, changed the default height value for the frame (350), changed the Frame_Scroll_Height value (65), and it worked perfectly.  I still need to adjust the scroll height dynamically to accommodate the variable amount of names.  

Thanks so much for your help!  For some reason I was definitely stuck on the idea that I needed to change both the height and scroll height.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40503987
I still need to adjust the scroll height dynamically to accommodate the variable amount of names.
Why? I didn't and it worked just fine. In any case you're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question