Link Scroll Bar to cells

mikebrooman

New Member
Joined
Jul 18, 2011
Messages
5
Afternoon,

I've been using this forum for ages, and so far it's answered every one of my questions just by searching.
But now I'm stumped.
This is due to my lack of VBA knowladge!

I'm trying to link a scroll bar to a max, min, and increments.
It is a stardards scrollbar (design mode > scroll bar).

The Max cell is C7,
Min cell is D7.
Increment cell is E7.

I know it's the lazy option, but I'm so bad at VBA I'm really hoping to be able to copy a code straight in.

Oh and one more little bit, these valuse (max min etc) will change depending on what item I select (they are linked themselfs), so I think I will need a work sheet change event (I read this, I have NO idea what it is!)

Thanks for your time.

Mike
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Changing formula result doesn't raise Worksheet_Change event. This means your variables won't be updated...
 
Upvote 0
try:

Code:
Private Sub ScrollBar1_BeforeDragOver(ByVal Cancel As MSForms.ReturnBoolean, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal DragState As MSForms.fmDragState, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
    With ScrollBar1
        .Max = [C7]
        .Min = [D7]
        .SmallChange = [E7]
        .LargeChange = [E7]
    End With
End Sub
 
Upvote 0
Thanks weaver,
The increment worked, but it still has a max of 32767 (not what is in c7) and a min of 0 (not in D7).
any clues?

try:

Code:
Private Sub ScrollBar1_BeforeDragOver(ByVal Cancel As MSForms.ReturnBoolean, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal DragState As MSForms.fmDragState, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
    With ScrollBar1
        .Max = [C7]
        .Min = [D7]
        .SmallChange = [E7]
        .LargeChange = [E7]
    End With
End Sub
 
Upvote 0
I'm not sure, it seemed to work when I was messing about with it, but I've deleted the sheet now. Maybe you could have a go at experimenting with some of the other events available.
 
Upvote 0
Thanks Weaver,
Maybe I'm misunderstanding where to put this code.
I right click on the scroll bar and then click view code, delete all the old code and past in the code you supplied. Then save and close VBA.
Is this right (I know it isn't how it mentions to do it in the link in your signiture, but this is for scroll bar not other macro)?

Thanks
 
Upvote 0
No that's right.

This all comes down to how we can trigger the change. I've had another look at this and think you might be able to do it under the 'scroll' event.

Code:
Private Sub ScrollBar1_Scroll()
The rest of the code stays the same.
You could probably update the .linkedcell property as well if you needed.

Of course, that's assuming your scrollbar is named 'ScrollBar1' ...
 
Upvote 0
Nice One :-)

works a treat!
I will learn VBA one day, probably just in time to retire!

Thanks

The reason I didn't go with this first was because I wasn't sure the parameters would update while the slider was active. Also, I'm not sure what happens say if you were to change the max value to a number that was less than what's already on the slider and vice versa with the min value.

I'd be interested to hear how you get on in this area.
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,551
Members
452,927
Latest member
rows and columns

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