excel - 如何隐藏和取消隐藏标签
问题描述
我有一份显示上个月信息的月度报告。(最终,我会将更新的信息提取到报告中。)
我希望自动隐藏上个月的标签并打开当月的标签。
例如:对于 2018 年 9 月。可见选项卡显示“Aug18”。我希望自动隐藏“Aug18”选项卡并取消隐藏“Sep18”选项卡。
解决方案
1) 将当前日期转换为我们可以用于测试“大于”类型逻辑 YYYYMM 的格式:
Dim currentDate As String
currentDate=Format(Now(), "YYYYMM")
2)循环浏览您的工作表:
Dim currentDate As String
currentDate=Format(Now(), "YYYYMM")
Dim ws as Worksheet
For Each ws in ThisWorkbook.Worksheets
Next ws
3)如果它是一个名为一个月的工作表,则在该循环内部进行转换测试。在这里使用InStr
:
Dim currentDate As String
currentDate = Format(Now(), "YYYYMM")
Dim ws As Worksheet
Dim thisTabDate As String
For Each ws In ThisWorkbook.Worksheets
'Test to see if this is in the right format
If InStr(1, "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", Left(ws.Name, 3)) Then
End If
Next ws
4)如果是,则将选项卡的名称格式化为相同的 YYYYMM 并设置其可见性
Dim currentDate As String
currentDate = Format(Now(), "YYYYMM")
Dim ws As Worksheet
Dim thisTabDate As String
For Each ws In ThisWorkbook.Worksheets
'Test to see if this is in the right format
If InStr(1, "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", Left(ws.Name, 3)) Then
'This is messy, but we are just cutting the tab name up, turning it into an actual date, and then formatting that.
thisTabDate = Format(CDate(Left(ws.Name, 3) & "-01-" & Right(ws.Name, 2)), "YYYYMM")
'Set the visible True/False to the result of the test
ws.Visible = (thisTabDate >= currentDate)
End If
Next ws
推荐阅读
- java - 在球衣中发布 +200MB 文件时出错
- c - 如何将结构成员作为引用传递给函数?
- python - Python 文件在 IDLE 中运行,但不是作为 EXE
- powershell - 使用 Power Shell 脚本的 Office 365 电子邮件活动用户报告
- javascript - 从 Angular 的表单组中删除特定的验证器
- webrtc - PeerJS 服务器 完全不工作?
- ruby-on-rails - ActiveRecord::StatementInvalid (PG::UndefinedTable: 错误: 关系“用户”不存在
- spring-boot - Spring Batch 动态块大小基于 CSV 中的行数,不计算标题行
- python - Arduino Client 通过 websocketsocket 连接到服务器但无法与之通信
- git - git push 后如何将 URL 返回到我的 git 存储库?