excel数据透视表如何创建导航工作表
时间:2023-04-23 21:55:48
当工作簿中的工作表不多时,我们只需要单击底部的工作表名到达想要操作的工作表。然而,当有很多工作表时,要找到想要的工作表就需要边单击滚动按钮边查找工作表,这可能要花点时间了。
其实,我们可以创建一个导航工作表,将工作簿中的所有工作表名称都放置到导航工作表中,并设置到工作表的链接,这样,我们只需要单击工作表名称,即可到达相对应的工作表。同时,在每个工作表中,放置回到导航工作表的链接,这样单击该链接就可以迅速回到导航工作表。这样更方便快捷,如下图1所示。
图1
实现上述功能的VBA代码如下:
Sub NavigateWorksheet()
Dim wks As Worksheet
Dim i As Integer
i = 0
‘如果存在”导航”工作表,则清除其内容
‘如果不存在”导航”工作表,则添加
If SheetExists(“导航”) Then
Cells.ClearContents
Worksheets(“导航”).Range(“A1”).Select
Else
Worksheets.Add before:=Worksheets(1)
ActiveSheet.Name = “导航”
End If
‘遍历工作表
For Each wks In Worksheets
i = i + 1
‘排除”导航”工作表
If i = 1 Then GoTo Continue
‘添加导航链接
With ActiveCell
.Value = wks.Name
.Hyperlinks.Add ActiveCell,””, _
wks.Name & “!A1″, _
TextToDisplay:=wks.Name, _
ScreenTip:=”单击返回导航工作表”
With Worksheets(i)
.Range(“A1″).Value =”返回到工作表: ” & ActiveSheet.Name
.Hyperlinks.AddSheets(wks.Name).Range(“A1”), “”, _
“‘” &ActiveSheet.Name & “‘” & “!” &ActiveCell.Address, _
ScreenTip:=”返回到工作表:” & ActiveSheet.Name
End With
End With
ActiveCell.Offset(1, 0).Select
Continue:
Next wks
End Sub
‘判断工作表是否存在
Function SheetExists(strName) As Boolean
Dim obj As Object
On Error Resume Next
Set obj = ActiveWorkbook.Sheets(strName)
If Err.Number = 0 Then
SheetExists = True
Else
SheetExists = False
End If
End Function
运行NavigateWorksheet过程,将在工作簿中创建一个名为“导航”的工作表(如果该工作表已存在,则清空其中的内容),然后在“导航”工作表的列A中输入该工作簿其他工作表的名称并建立到该工作表的链接,同时在其他工作表的单元格A1中创建返回“导航”工作表的链接。
代码的图片版如下:
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
word 压缩文档图片的方法图解教程
![](https://img.aspxhome.com/file/2023/3/33073_0s.jpg)
图文讲解:Word2007界面简介
![](https://img.aspxhome.com/file/2023/0/29250_0s.jpg)
Word2017怎么使用剪贴画中的图形? word插入剪贴画的教程
![](https://img.aspxhome.com/file/2023/0/22690_0s.jpg)
word如何实现两列排版
![](https://img.aspxhome.com/file/2023/0/35260_0s.png)
word 页面添加水印的方法 图解教程
![](https://img.aspxhome.com/file/2023/1/32641_0s.jpg)
Win10打开文件夹缓慢或假死如何解决?
![](https://img.aspxhome.com/file/2023/4/52524_0s.jpg)
word删除分节符的方法步骤图
iOS 14测试版值得升吗?iOS 14升级体验怎么样?
![](https://img.aspxhome.com/file/2023/8/a194988_0s.jpg)
MathType在word中常见问题的解决技巧
![](https://img.aspxhome.com/file/2023/7/32327_0s.jpg)
win10投影仪如何铺满全屏?win10投影仪铺满全屏的方法
![](https://img.aspxhome.com/file/2023/9/47619_0s.png)
Win10威胁服务已经停止立即重启怎么解决?
![](https://img.aspxhome.com/file/2023/7/51037_0s.jpg)
word文档中怎么设置页眉页脚
如何拯救word标题黑块
![](https://img.aspxhome.com/file/2023/8/32138_0s.jpg)
Windows10升级到2004版本后无法连接网络怎么解决?
![](https://img.aspxhome.com/file/2023/8/50068_0s.jpg)
如何设置防止excel跳过空格录入数据
![](https://img.aspxhome.com/file/2023/4/38094_0s.png)
Word2007如何添加动态文字
excel表格密码怎么设置与取消?
![](https://img.aspxhome.com/file/2023/3/42633_0s.jpg)
Win10电脑要怎么还原电脑系统?
![](https://img.aspxhome.com/file/2023/8/51748_0s.png)
在Excel表格中怎么分列?
![](https://img.aspxhome.com/file/2023/6/40996_0s.jpg)
"Microsoft Office Word已停止工作"终极解决方案(图文教程)
![](https://img.aspxhome.com/file/2023/8/21148_0s.jpg)