Vincent88
Active Member
- Joined
- Mar 5, 2021
- Messages
- 382
- Office Version
- 2019
- Platform
- Windows
- Mobile
I use below code to duplicate a worksheet with a dynamic table, then clear all contents, embedded items and pictures of whole sheet but I need to copy all headers' value of the table back to new sheet but failed. Need help !
CODE
Sub BlankSheet()
If ActiveWorkbook Is ThisWorkbook Then
Dim ws As Worksheet
Set ws = ActiveSheet
Dim LastColumn As Long
LastColumn = ws.Range("A1").CurrentRegion.Columns.Count
On Error Resume Next
Application.DisplayAlerts = False
ws.Range(Cells(1, 1), Cells(1, LastColumn)).Copy
ws.Copy before:=ActiveSheet
szToday = Format(Date, "d mmm yyyy")
ActiveSheet.name = szToday
Application.DisplayAlerts = True
'Clear All Contents
ActiveSheet.Cells.ClearContents
ActiveSheet.OLEObjects.Visible = True
ActiveSheet.OLEObjects.Delete
ActiveSheet.Pictures.Visible = True
ActiveSheet.Pictures.Delete
ActiveSheet.Range(Cells(1, 1)).Paste
End If
End Sub
CODE
Sub BlankSheet()
If ActiveWorkbook Is ThisWorkbook Then
Dim ws As Worksheet
Set ws = ActiveSheet
Dim LastColumn As Long
LastColumn = ws.Range("A1").CurrentRegion.Columns.Count
On Error Resume Next
Application.DisplayAlerts = False
ws.Range(Cells(1, 1), Cells(1, LastColumn)).Copy
ws.Copy before:=ActiveSheet
szToday = Format(Date, "d mmm yyyy")
ActiveSheet.name = szToday
Application.DisplayAlerts = True
'Clear All Contents
ActiveSheet.Cells.ClearContents
ActiveSheet.OLEObjects.Visible = True
ActiveSheet.OLEObjects.Delete
ActiveSheet.Pictures.Visible = True
ActiveSheet.Pictures.Delete
ActiveSheet.Range(Cells(1, 1)).Paste
End If
End Sub