Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.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
Excel 基于日期值显示/隐藏工作表的宏_Excel_Export To Excel_Vba - Fatal编程技术网

Excel 基于日期值显示/隐藏工作表的宏

Excel 基于日期值显示/隐藏工作表的宏,excel,export-to-excel,vba,Excel,Export To Excel,Vba,我有一个excel工作簿,它是由一个可执行文件创建的,在单独的工作表上有每月几天的数据。”可执行文件的表1'也列出了月份的天数。我想写一个宏,根据“工作表1”中的日期显示/隐藏工作表 例如,如果一月的数据显示了第1、2、3、4、5、11、12天,则宏应仅显示第1天、第2天、第3天、第4天、第5天的相应工作表,并隐藏第6天到第10天,并显示第11天和第12天。任何指点都很感激 谢谢。公共子设置表可见性() public sub setSheetVisiblity() 'Load the da

我有一个excel工作簿,它是由一个可执行文件创建的,在单独的工作表上有每月几天的数据。”可执行文件的表1'也列出了月份的天数。我想写一个宏,根据“工作表1”中的日期显示/隐藏工作表

例如,如果一月的数据显示了第1、2、3、4、5、11、12天,则宏应仅显示第1天、第2天、第3天、第4天、第5天的相应工作表,并隐藏第6天到第10天,并显示第11天和第12天。任何指点都很感激

谢谢。

公共子设置表可见性()
public sub setSheetVisiblity()

  'Load the data from sheet 1 into a collection
  'I'm making the assumption that you just have days listed horizontally from 
  '1A to 1*

  Dim currentColumn as Integer
  Dim activeDayCollection as Collection

  currentColumn = 1
  Set activeDayCollection = new Collection

  While Cells(currentColumn, 1).Value <> ""

    activeDayCollection.add Cells(currentColumn, 1).Value 

    currentColumn = currentColumn + 1
  Wend

  'Make every sheet invisible/visible
  For each currentWorksheet as Worksheet in Worksheets

    If currentWorksheet.Name == "Day" + activeDayCollection.Item 1 Then
      currentWorksheet.Visible = true
      activeDayCollection.Remove 1
    Else
       currentWorksheet.Visible = false
    End If

  Next currentWorksheet
end sub
'将表1中的数据加载到集合中 我的假设是,你只是水平列出了从 '1A至1* 将currentColumn设置为整数 将activeDayCollection设置为集合 currentColumn=1 Set activeDayCollection=新集合 While单元格(currentColumn,1)。值“” activeDayCollection.add单元格(currentColumn,1).Value currentColumn=currentColumn+1 温德 '使每张图纸不可见/可见 将每个当前工作表作为工作表中的工作表 如果currentWorksheet.Name==“Day”+activeDayCollection.Item 1,则 currentWorksheet.Visible=true activeDayCollection。删除1 其他的 currentWorksheet.Visible=false 如果结束 下一个当前工作表 端接头
该代码的工作原理是假设第一张工作表中的天数按递增顺序排列,工作表名为Day####,其中###是天数,您可能需要添加另一行来手动取消隐藏第一张工作表。我没有带vba,因此这段代码可能有一些语法错误,但它应该能让您朝着正确的方向前进。

public sub-setSheetVisiblity()
'将表1中的数据加载到集合中
我的假设是,你只是水平列出了从
'1A至1*
将currentColumn设置为整数
将activeDayCollection设置为集合
currentColumn=1
Set activeDayCollection=新集合
While单元格(currentColumn,1)。值“”
activeDayCollection.add单元格(currentColumn,1).Value
currentColumn=currentColumn+1
温德
'使每张图纸不可见/可见
将每个当前工作表作为工作表中的工作表
如果currentWorksheet.Name==“Day”+activeDayCollection.Item 1,则
currentWorksheet.Visible=true
activeDayCollection。删除1
其他的
currentWorksheet.Visible=false
如果结束
下一个当前工作表
端接头

该代码的工作原理是假设第一张工作表中的天数按递增顺序排列,工作表名为Day####,其中###是天数,您可能需要添加另一行来手动取消隐藏第一张工作表。我没有带vba,所以这段代码可能有一些语法错误,但它应该能让您朝着正确的方向前进。

到目前为止,您有什么发现?创建宏的一个很好的起点是录制一个宏并执行您想要完成的操作。它将为您需要调用的函数提供大量输入。到目前为止,您有哪些功能?创建宏的一个很好的起点是录制一个宏并执行您想要完成的操作。它将为您需要调用的函数提供大量输入