1

I'm new to 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.

Any help is greatly appreciated.
Thanks Ted

2 Answers 2

2

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 
Sign up to request clarification or add additional context in comments.

Comments

0

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 

1 Comment

I stepped through the code and it works up til this point Ws.Range("Pipeline[#All]").Copy newWs.Range("a1") Ws.Visible = xlSheetHidden It appears to be pasting the whole sheet and not the selected part as per this code 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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.