[英]VBA to create, rename and paste into a new sheet
I'm new to VBA. 我是VBA的新手。
I'm looking to create some code that will filter a table on one sheet copy this then paste into a new sheet, whilst that new sheet has been renamed with today's date, then hiding the existing sheet again. 我正在寻找创建一些代码,该代码将过滤一张工作表上的表格,然后将其复制并粘贴到新工作表中,而新工作表已使用今天的日期进行了重命名,然后再次隐藏现有工作表。 This is need weekly and possibly daily. 这是每周一次,可能每天一次。
So far I have 到目前为止,我有
Sub test2()
'
' test2 Macro
'
'
ActiveSheet.ListObjects("Pipeline").Range.AutoFilter Field:=1, Criteria1:= _
"<>"
Range("Pipeline[[#Headers],[FC]]").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Dim SheetName As String
SheetName = Format(Date, "dd-mm-yyyy") 'Change the format as per your requirement
Sheets.Add , Worksheets(Worksheets.Count)
ActiveSheet.Name = SheetName
End Sub
This is filtering the range in the table and copying, and also creating the new worksheet. 这将过滤表中的范围并进行复制,并创建新的工作表。 But how do I then past into the new sheet then hide the sheet again. 但是,我该如何进入新工作表,然后再次隐藏工作表。 Ideally I suppose the code needs to unhide the sheet to begin with. 理想情况下,我认为代码需要先取消隐藏工作表。 The sheet name is FC_Pipeline
. 工作表名称为FC_Pipeline
。
Any help is greatly appreciated. 任何帮助是极大的赞赏。
Thanks Ted 谢谢特德
This is to hide and create a new sheet with today's date 这是为了隐藏并创建具有今天日期的新工作表
Sub Makro()
Dim currentSheet As String
currentSheet = ActiveSheet.Name
Dim SheetName As String
SheetName = Format(Date, "dd-mm-yyyy")
Sheets.Add After:=ActiveSheet
ActiveSheet.Name = SheetName
Sheets(currentSheet).Visible = False
End Sub
I think the code would be like this 我认为代码会像这样
Sub test2()
Dim Ws As Worksheet, newWs As Worksheet
Dim SheetName As String
Set Ws = ActiveSheet
ActiveSheet.ListObjects("Pipeline").Range.AutoFilter Field:=1, Criteria1:="<>"
SheetName = Format(Date, "dd-mm-yyyy") 'Change the format as per your requirement
Sheets.Add , Worksheets(Worksheets.Count)
ActiveSheet.Name = SheetName
Set newWs = ActiveSheet
Ws.Range("Pipeline[#All]").SpecialCells(xlCellTypeVisible).Copy newWs.Range("a1")
Ws.Visible = xlSheetHidden
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.