提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何保持与Excel工作表滚动的数据透视表切片器?

在使用数据透视表时,您可以插入切片器来对数据进行可视化的表格过滤。 本文正在讨论在滚动工作表时总是可见Pivot Table的切片器。

保持数据透视表的切片器随工作表一起移动,并使用VBA代码进行滚动

Office选项卡在Office中启用选项卡式编辑和浏览,使您的工作更轻松......
Kutools for Excel解决了您的大多数问题,并使您的生产率提高了80%
  • 重用任何东西: 将最常用或最复杂的公式,图表和其他任何内容添加到您的收藏夹中,并在将来快速重复使用它们。
  • 超过20文本功能: 从文本字符串中提取数字; 提取或删除部分文本; 将数字和货币转换为英语单词...
  • 合并工具:多个工作簿和表格合二为一; 合并多个单元格/行/列而不丢失数据; 合并重复行和总和...
  • 拆分工具:根据价值将数据拆分为多个表格; 一个工作簿到多个Excel,PDF或CSV文件; 一列到多列......
  • 粘贴跳过 隐藏/过滤行; 数和总和 按背景颜色; 创建邮件列表和 通过Cell的价值发送电子邮件...
  • 超级过滤器: 创建高级过滤方案并应用于任何工作表; 排序 按周,日,频率等; 筛选 通过大胆,公式,评论......
  • 超过300强大的功能; 与Office 2007-2019和365一起使用; 支持所有语言; 在您的企业或组织中轻松部署。

箭头蓝色右泡保持数据透视表的切片器随工作表一起移动,并使用VBA代码进行滚动


下面的VBA脚本可以帮助您保持Pivot Table的切片器随工作表一起移动。 请做如下。

1。 按 其他 + F11 键同时打开 Microsoft Visual Basic for Applications 窗口。

2。 在里面 Microsoft Visual Basic for Applications 窗口,双击 的ThisWorkbook 在左侧的“项目”窗格中,然后将以下VBA代码复制并粘贴到 ThisWorkbook(Code) 窗口。 看截图:

VBA代码:保持数据透视表的切片器随着工作表滚动而移动

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Dim ShF As Shape
    Dim ShM As Shape
    'specify a slicer
    Application.ScreenUpdating = False
    Set ShF = ActiveSheet.Shapes("Column1")
    Set ShM = ActiveSheet.Shapes("Column2")
    'change position of the slicer
    With Windows(1).VisibleRange.Cells(1, 1)
        ShF.Top = .Top
        ShF.Left = .Left + 300
        ShM.Top = .Top
        ShM.Left = .Left + 100
    End With
    Application.ScreenUpdating = True
End Sub

笔记:

1)。 在代码中,Column1和Column2是切片机的名称。

2)。 您可以在代码中滚动工作表时指定切片器的位置。

3)。 您可以在代码中添加更多切片器,或者根据需要从其中删除切片器。

3。 按 其他 + Q 键关闭 Microsoft Visual Basic for Applications 窗口对话框。

从现在开始,滚动工作表时,指定的切片器将与活动单元一起移动。 看截图:


箭头蓝色右泡相关文章:


Kutools for Excel解决了您的大多数问题,并使您的生产率提高了80%

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能30天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    MICHAEL · 1 years ago
    I have 4 slicers which have been grouped together by selecting all 4 and the right clicking to use the group command.

    Is it possible to assign this VBA by a group? How do you label the group and write the VBA to recognize it as one?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Michael,
      Sorry can't help with this. Thanks for your comment.
  • To post as a guest, your comment is unpublished.
    Katie · 1 years ago
    What does the first row indicate and how do we customize it to suit our slicer?
    I'm very confused about that on basically every line.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Dear Katie
      I don't know if I totally understand your question.
      As I mentioned in above Notes, you need to replace Column1 and Column2 with the names of your slicers in the code in order to keep your slicer scrolling with the worksheet.
  • To post as a guest, your comment is unpublished.
    John Fernandes · 1 years ago
    Hi,
    Thank you for this VBA.

    I have absolutely no idea about VBA and hence my question.

    I used this VBA and I had a question.
    How can i alter this VBA so that it works only for one sheet.

    Right now, I have 8 sheets and every time i go to another sheet, it fails and asks me to end or debug.
    I have done exactly the way as shown above.


    This is my VBA here..
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Dim ShF As Shape
    Dim ShM As Shape
    'specify a slicer
    Application.ScreenUpdating = False
    Set ShF = ActiveSheet.Shapes("Client 1")
    Set ShM = ActiveSheet.Shapes("Reminder 1")
    'change position of the slicer
    With Windows(1).VisibleRange.Cells(1, 1)
    ShF.Top = .Top + 2
    ShF.Left = .Left + 475
    ShM.Top = .Top + 180
    ShM.Left = .Left + 475
    End With
    Application.ScreenUpdating = True
    End Sub


    Please help.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Dear John,
      Shift to the worksheet you want the VBA code only work for, then right click the Sheet tab and select View Code from the context menu.
      And then copy and paste below VBA code into the opening Code window. See below screenshot:

      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Dim ShF As Shape
      Dim ShM As Shape
      'specify a slicer
      Application.ScreenUpdating = False
      Set ShF = ActiveSheet.Shapes("Fruit")
      Set ShM = ActiveSheet.Shapes("Sale")
      'change position of the slicer
      With Windows(1).VisibleRange.Cells(1, 1)
      ShF.Top = .Top
      ShF.Left = .Left + 300
      ShM.Top = .Top
      ShM.Left = .Left + 100
      End With
      Application.ScreenUpdating = True
      End Sub
      • To post as a guest, your comment is unpublished.
        John · 1 years ago
        Dear Crystal,

        Thank you so very much for the code.
        I did exactly as you said and it works like a charm.

        Really appreciate it.
        Cheers :)
  • To post as a guest, your comment is unpublished.
    John · 1 years ago
    Hi,
    Thank you for this VBA.

    I have absolutely no idea about VBA and hence my question.

    I used this VBA and I had a question.
    How can i alter this VBA so that it works only for one sheet.

    Right now, I have 8 sheets and every time i go to another sheet, it fails and asks me to end or debug.
    I have done exactly the way as shown above.


    This is my VBA here..
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Dim ShF As Shape
    Dim ShM As Shape
    'specify a slicer
    Application.ScreenUpdating = False
    Set ShF = ActiveSheet.Shapes("Client 1")
    Set ShM = ActiveSheet.Shapes("Reminder 1")
    'change position of the slicer
    With Windows(1).VisibleRange.Cells(1, 1)
    ShF.Top = .Top + 2
    ShF.Left = .Left + 475
    ShM.Top = .Top + 180
    ShM.Left = .Left + 475
    End With
    Application.ScreenUpdating = True
    End Sub


    Please help.