Creating Dynamic Scrollbars using array

raven1124

New Member
Joined
Jun 13, 2017
Messages
29
Hello Everyone,

Need your help with aligning the scrollbars I created as I am creating dynamic shapes that should align each scrollbars in their respective subitems

Feel free to run my code

I created two sheets for this one:
- Database
- Sheet3

Database has this content:

OwnerRoleReporting ToItemStart DateEnd DateItem CountProgress
Name1Level 1alksdjlskaj7/1/20187/31/20189562
Name2Level 2fgdfgdgfdg7/1/20183023
Name3Level 2dgwwfws7/1/20182011
Name4Level 2Tasdaas7/1/20183013
Name5Level 2Osdasad7/1/20181515
Employee 1Level 3Name2Quality Sub Item 154
Employee 2Level 3Name2Quality Sub Item 153
Employee 3Level 3Name2Quality Sub Item 2106
Employee 123Level 3Name2Quality Sub Item 2106
Employee 4Level 3Name2Quality Sub Item 41010
Employee 5Level 3Name3Integrity Sub Item 1106
Employee 6Level 3Name3Integrity Sub Item 2105
Employee 7Level 3Name4Training Sub Item 150
Employee 8Level 3Name4Training Sub Item 252
Employee 9Level 3Name4Training Sub Item 352
Employee 10Level 3Name4Training Sub Item 452
Employee 11Level 3Name4Training Sub Item 5107
Employee 12Level 3Name5OMD Sub Item 155
Employee 13Level 3Name5OMD Sub Item 255
Employee 14Level 3Name5OMD Sub Item 355

<tbody>
</tbody>


Code:
Sub CreateShapes()


Dim ProjectSheet As Worksheet
Set ProjectSheet = ActiveSheet


Dim SupCounter() As String
Dim SupName() As String
Dim SubItem() As String


Dim miniextraScroll As MSForms.ScrollBar


Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim counter1 As Integer
Dim counter2 As Integer
Dim counter3 As Integer


Dim asd As Integer
Dim m As Integer
Dim duplicount As Integer


Dim mfShape As Shape
Dim mfShade As Shape
'Dim qwe As Integer
'qwe = 1


x = 1
Do While Database.Cells(x, 1) <> ""
    If Database.Cells(x, 2) = "Level 2" Then
        counter1 = counter1 + 1
        ReDim Preserve SupCounter(counter1 - 1)
        SupCounter(counter1 - 1) = Database.Cells(x, 4)
        ReDim Preserve SupName(counter1 - 1)
        SupName(counter1 - 1) = Database.Cells(x, 1)
        
        'Create Shape
         Set mfShade = ProjectSheet.Shapes.AddShape(msoShapeRoundedRectangle, 10 + (counter1 - 1) * 5 * 20, 50, 75, 13)
            With mfShade
                .Name = SupCounter(counter1 - 1)
                .Line.Visible = msoFalse
                .Fill.ForeColor.RGB = RGB(54, 56, 60)
            End With
            
        Set mfShape = ProjectSheet.Shapes.AddShape(msoShapeRoundedRectangle, 10 + (counter1 - 1) * 5 * 20, 50, mfShade.Width, 13)
            With mfShape
                .Name = SupCounter(counter1 - 1) & " Shape"
                .Line.Visible = msoFalse
                .Fill.ForeColor.RGB = RGB(8, 146, 208)
            End With
        
        
            y = 1
            asd = 0
            Do While Database.Cells(y, 1) <> ""
                
                
                
                If Database.Cells(y, 2) = "Level 3" And Database.Cells(y, 3) = SupName(counter1 - 1) Then
                    counter2 = counter2 + 1
                    asd = asd + 1
                    ReDim Preserve SubItem(counter2 - 1)
                    SubItem(counter2 - 1) = Database.Cells(y, 4)
                        
                        'Mini Shapes
                        'If qwe = 1 Then
                        For m = 0 To UBound(SubItem)
                            If SubItem(m) = SubItem(counter2 - 1) Then
                                duplicount = duplicount + 1
                            Else
                            End If
                            'MsgBox ("M: " & m & "Upperbound: " & UBound(SubItem) & "Duplicount: " & duplicount)
                            
                            
                        Next m
                        
                        
                        If duplicount = 1 Then
                        Set mfShade = ProjectSheet.Shapes.AddShape(msoShapeRoundedRectangle, 10 + (counter1 - 1) * 5 * 20, Sheet3.Shapes(SupCounter(counter1 - 1)).Top + 15 * asd, 75, 7)
                        With mfShade
                            .Name = SubItem(counter2 - 1)
                            .Line.Visible = msoFalse
                            .Fill.ForeColor.RGB = RGB(54, 56, 60)
                        End With
                        End If
                        
                        Dim a As Integer
                        
                        a = WorksheetFunction.CountIf(Database.Range("D:D"), SubItem(counter2 - 1))
                        
                        
                        
                        duplicount = 0
                        
                        
                        
                        Dim MyObject As OLEObject
                        Set MyObject = ActiveSheet.OLEObjects.Add(ClassType:="Forms.ScrollBar.1")
                                With MyObject
                                    .Name = "ScrollBar" & counter1 & counter2
                                    .Height = 7
                                    .Width = 75
                                    .Top = 7 + (Sheet3.Shapes(SubItem(counter2 - 1)).Top) * (y * 0.15)
                                    .Left = Sheet3.Shapes(SupCounter(counter1 - 1)).Left
                                        With .Object
                                        .Value = 2
                                        .Max = 5
                                        .Min = 0
                                        End With
                                End With
                        
                      
                        
                
                Else
                
                End If
            
                
            
            y = y + 1
            Loop
            
    Else


    End If


x = x + 1
Loop




End Sub
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,214,998
Messages
6,122,643
Members
449,093
Latest member
Ahmad123098

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