How to Dynamically Change the Size of a Frame and Scrollbar on an Excel UserForm
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.
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
Phillip Burton
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.
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.
Martin Liss
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?
Quiver
ASKER
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.
Here's what I see when I unpack your zip file. 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?
Quiver
ASKER
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.
Quiver
ASKER
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.
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.
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.
For example:
UserForm_search.Frame1.Hei
reduces the height significantly.