disabling and enabling ActiveX scrollbar using loops

FrustratedEland

New Member
Joined
Jul 12, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Im very frustrated as I am sure that this is very simple, but I can't quite pull this one together!

I would like to check against a row of four values that start in A1 - if there is a 1, I would like the corresponding scrollbar (Bars 1 to 4) to be activated, and if there is a 0, to be disabled. I have something in mind along the lines below, and would grateful for any help! This version obviously isnt correct but I cannot find the right format to select the correct bar for the life of me - an earlier attempt didnt have any errors but was reading the bar values which was lovely but not really what I was after! Thank you .

VBA Code:
Private Sub EnableScrolls()
Dim i As Long
Dim Sc As ScrollBar

For i = 1 To 4
Sc = ("Bar" & i)
With Sheet1.Range("A1").Cells(1, i)
        If Sheet1.Range("A1").Cells(1, i) = "1" Then
            Sc.Enabled = True
        Else
            Sc.Enabled = False
        End If
End With
Next i
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
@FrustratedEland
Try:
VBA Code:
Private Sub EnableScrolls()
Dim i As Long
Dim Sc As Object

For i = 1 To 4
    Set Sc = Sheets("Sheet1").OLEObjects("Scrollbar" & i).Object
    With Sheet1.Range("A1").Cells(1, i)
            If Sheet1.Range("A1").Cells(1, i) = 1 Then
                Sc.Enabled = True
            Else
                Sc.Enabled = False
            End If
    End With
Next i
End Sub
 
Upvote 0
Solution
This is absolutely brilliant, thank you. I managed a temporary workaround using shapes.visible, which allowed me to tick through the scrollbar names without throwing errors. However this is what I intended and I would never have got to OLEObjects on my own.
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,215,831
Messages
6,127,145
Members
449,363
Latest member
Yap999

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