0

我在 ThisWorkbook 中有一些 VB 代码,可以在滚动时将切片器向上移动。

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim ShF As Shape
Dim ShM As Shape
Dim ShN As Shape
Dim ShO As Shape
Dim SHP As Shape
'specify a slicer
Application.ScreenUpdating = True
Set ShF = ActiveSheet.Shapes("Segment")
Set ShM = ActiveSheet.Shapes("Promotional Status")
Set ShN = ActiveSheet.Shapes("BNPL Scheme")
Set ShO = ActiveSheet.Shapes("APR")
Set SHP = ActiveSheet.Shapes("Control Group ")

'change position of the slicer
With Windows(1).VisibleRange.Cells(1, 1)
    ShF.Top = .Top + 7
    ShF.Left = .Left + 7
    ShM.Top = .Top + 102
    ShM.Left = .Left + 7
    ShN.Top = .Top + 220
    ShN.Left = .Left + 7
    ShO.Top = .Top + 320
    ShO.Left = .Left + 7
    SHP.Top = .Top + 418
    SHP.Left = .Left + 7
End With
Application.ScreenUpdating = True
End Sub

当我在切片机打开的工作表上时,它工作得非常好,但是当我转到另一个选项卡时,我收到错误“找不到具有指定名称的项目”。我实际上只在 sheet1 上需要它,而不是在整个工作簿上。

4

0 回答 0