Userform Objects During Runtime

raven1124

New Member
Joined
Jun 13, 2017
Messages
29
Hello,

I just started learning how to create objects during runtime and I am currently having a problem with creating multiple frames horizontally and I can't seem to line them up properly as each frames has their own width. Can someone help me out with creating multiple frames considering that the first frame should start at "Left = 5" then move the next frame on its right without overlapping each other and with the right amount of margin?

Here's my initial code below:
Code:
For counter = 1 To 3

    Set extraFrame = Userform1.Controls.Add("Forms.Frame.1", "Frame" & counter, True)
         With extraFrame
            .Name = ""
            .Top = 20
            .Left = 5 * counter
            .Width = 100
            .Height = 25
        End With

Next counter
 
Last edited:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Maybe
Code:
For Counter = 0 To 2

    Set extraFrame = UserForm1.Controls.Add("Forms.Frame.1", "Frame" & Counter, True)
         With extraFrame
            .name = ""
            .Top = 20
            .Left = 5 + 100 * Counter
            .Width = 100
            .Height = 25
        End With

Next Counter
 
Upvote 0
First of all, thank you!

I didn't thought about changing the counter to 0 considering the width value.

I have a follow up question, is there any changes to adjust the border in between frames?
 
Upvote 0
How about
Code:
            .Left = 5 + 105 * Counter
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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