Scrolling in a UserForm Frame by a Code

rajsingh0621

New Member
Joined
Feb 28, 2010
Messages
24
Is it possible to scroll down in a UserForm Frame with a VBA Code in excel. My frame in the userform has a scrollheight of 600 and a lot of option buttons. Based on a selection in a ComboBox(using If statement), I'd like to scroll down to a certain amount in the Frame. Does anybody have any idea on it.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Something like this?
Code:
Sub scrollFrame(topVisibleControl As Object)
    Frame1.ScrollTop = topVisibleControl.Top
End Sub

Private Sub CommandButton1_Click()
    Call scrollFrame(OptionButton8)
End Sub
 
Upvote 0
To respond to the confusion that you mentioned in your thankful PM.

The .Top (and .Left) property of a control in a Frame (or MultiPage) is relative to that Frame, not the UserForm.

The .ScollTop property of a Frame is the .Top of the visible portion of a scrolled Frame (relative to the Frame).
 
Upvote 0
So the code works, but I still can't fully understand it. So far I haven't learned any functions in vba, but I thought only in functions you put something in the () after sub. Over here you have topvisiblecontrol as Object in the parenthesis.. So tobvisiblecontrol is the variable. But how come Dim topvisiblecontrol as Object doesn't work if I write it in the next line.

Then you say Call ScrollFrame(OptionButton#), so I understand this part that it calls the ScrollFrame macro, but I still don't understand why we're putting the OptionButton# in the parenthesis.
 
Upvote 0
I also just tried.
If ComboBox1 = 1 Then
Frame1.ScrollTop = OptionButton3.Top
End if

But I'd still like to understand the other macro fully.
 
Upvote 0
"how come Dim topvisiblecontrol as Object doesn't work if I write it in the next line."
A variable has to be declared before it is used.
When a variable is the argument of a procedure, the procedure declaration statement also declares the variables that

Code:
Sub scrollFrame(topVisibleControl As Object)
' Declares sub named scrollFrame and (procedure scoped) variable named topVisibleControl
 
Upvote 0
Code:
Sub scrollFrame(topVisibleControl As Object)
    Frame1.ScrollTop = topVisibleControl.Top
End Sub

Private Sub CommandButton1_Click()
    Call scrollFrame(OptionButton8)
End Sub

Thanks for this.
Not sure why this was not a built in control in the first place but your work around works fine.
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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