Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms 从vba一次添加多个窗体按钮滚动条_Forms_Vba_Excel - Fatal编程技术网

Forms 从vba一次添加多个窗体按钮滚动条

Forms 从vba一次添加多个窗体按钮滚动条,forms,vba,excel,Forms,Vba,Excel,我需要下面的宏引用另一个子更改事件,以循环引用滚动条的行号,然后调整单元格Bi。到目前为止,我只能得到100个滚动条,仅供参考 Sub Tester88() Dim ScrollBar As Object Dim rng As Range Dim i As Long Dim lastRow As Long lastRow = 99 'Modify as needed this will be the last possible row to add a

我需要下面的宏引用另一个子更改事件,以循环引用滚动条的行号,然后调整单元格
Bi
。到目前为止,我只能得到100个滚动条,仅供参考

Sub Tester88()
    Dim ScrollBar As Object
    Dim rng As Range
    Dim i As Long
    Dim lastRow As Long

    lastRow = 99 'Modify as needed this will be the last possible row to add a button

    For i = 2 To lastRow Step 4
        Set rng = ActiveSheet.Cells(i, 18)  'Column 3, row i

        '## Create the button object and assign a variable to represent it
        Set ScrollBar = ActiveSheet.ScrollBars.Add(1, 1, 1, 1)

        '## use the btn variable to manipulate the button:
        With ScrollBar
            .Top = rng.Top
            .Left = rng.Left
            .width = rng.width
            .height = rng.RowHeight
            .Value = 1
            .Min = 1
            .Max = 100
            .SmallChange = 1
            .LargeChange = 10
            .LinkedCell = "$B$2"
            .Display3DShading = True

        End With
    Next
End Sub

看起来您可以将该行放入.LinkedCell,而不是硬编码。您已将其设置为1-100的范围;请记住,如果使用LinkedCell,则直接控制单元格的值,因此如果控制具有一组现有值的数据,则需要将范围(和值)设置为单元格的现有值,或者将其作为仅显示滚动条值的单元格,并使用引用该单元格的公式获得最终结果。+//p>我已解决此任务,因此:

Sub Tester88()
    Dim ScrollBar As Object
    Dim rng As Range
    Dim i As Long
    Dim lastRow As Long

    lastRow = 99 'Modify as needed this will be the last possible row to add a button

    For i = 2 To lastRow Step 4
        Set rng = ActiveSheet.Cells(i, 13)  'Column 3, row i

        '## Create the button object and assign a variable to represent it
        Set ScrollBar = ActiveSheet.ScrollBars.Add(1, 1, 1, 1)

        '## use the btn variable to manipulate the button:
        With ScrollBar
            .Top = rng.Top
            .Left = rng.Left
            .Width = rng.Width
            .Height = rng.RowHeight
             .Min = 1
        .Max = 100
        .SmallChange = 1
    .LargeChange = 1
    .LinkedCell = "B" & i

        End With
    Next
End Sub

o我不知道怎么做。请问与该问题中的按钮问题相关的问题,而不是这个问题。由于此解决方案使用链接单元格而不是事件处理程序,因此不相关。你确定这是延误的原因吗?如果您将所有内容硬编码到第7行或其他任何地方,那么速度会更快吗?您不知道如何实现这一点是什么意思?这是一个简单的字符串操作,
“$B$”+CStr(i)
-你有任何编程经验吗?谢谢,我会尝试的-我尝试过“Bi”和“B&i”,无论你做什么,它都需要在引号之外,或者它只是字符串的一部分。