Share via

ActiveX Scroll Bar increment change based on value

Anonymous
2018-09-14T15:55:25+00:00

I'm pretty new when it comes to Visual Basic, so excuse me if my code is horrid.

I'm trying to implement a scroll bar where the incremental value (SmallChange and LargeChange) changes as the value increases decreases. I've tried if statements in different form but have not had much success. The best I got was that the increment properties changed (based on a value off of another cell) but for some reason the scroll bar itself still didn't work as it should have. 

Anyways, here's the code I got:

This is what 'works' but isn't what I want, (also just a test of numbers)

Private Sub ScrollBar1_Change()

If Sheet1.Range("D4") <= 100 Then

    Sheet1.ScrollBar1.SmallChange = 1

    Sheet1.ScrollBar1.LargeChange = 5

ElseIf Sheet1.Range("D4") = 1000 Then

    Sheet1.ScrollBar1.SmallChange = 100

    Sheet1.ScrollBar1.LargeChange = 50

End If

End Sub

This is more what I want but doesn't work,

Private Sub ScrollBar1_Change()

If Sheet1.ScrollBar1.Value <= 1 Then

    Sheet1.ScrollBar1.SmallChange = 0.1

    Sheet1.ScrollBar1.LargeChange = 0.5

ElseIf Sheet1.ScrollBar1.Value <= 100 Then

    Sheet1.ScrollBar1.SmallChange = 1

    Sheet1.ScrollBar1.LargeChange = 5

ElseIf Sheet1.ScrollBar1.Value <= 1000 Then

    Sheet1.ScrollBar1.SmallChange = 50

    Sheet1.ScrollBar1.LargeChange = 10

End If

End Sub

Moved From: Excel / Windows 10 / Office 365 Home

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2018-09-15T07:33:03+00:00

    Probably should be something more like

    If Sheet1.ScrollBar1.Value <= 1 Then

        Sheet1.ScrollBar1.SmallChange = 0.1

        Sheet1.ScrollBar1.LargeChange = 0.5

    ElseIf Sheet1.ScrollBar1.Value > 1 And Sheet1.ScrollBar1,Value <= 100 Then

        Sheet1.ScrollBar1.SmallChange = 1

        Sheet1.ScrollBar1.LargeChange = 5

    ElseIf Sheet1.ScrollBar1.Value > 100 and Sheet1.ScrollBar1.Value <= 1000 Then

        Sheet1.ScrollBar1.SmallChange = 50

        Sheet1.ScrollBar1.LargeChange = 10

    'Else

        'What about if Sheet1.ScrollBar1.Value > 1000End If

    Was this answer helpful?

    0 comments No comments