Hello, please help in modifying the code. I want to copy . sheet TTC to the same file and rename it to the last value in column A in Sheet DATA The code works, the problem .Copies are done, but the formatting and the size of columns and rows are lost, what is the solution?
Please help in modifying the code or provide me with a code that does the same task
Please help in modifying the code or provide me with a code that does the same task
VBA Code:
Option Explicit
Private Sub newSheet_Click()
Dim lastLine As Integer
Dim nameSheet As String
Dim nok As Boolean
lastLine = ThisWorkbook.Sheets("DATA").Range("A" & Rows.Count).End(xlUp).Row
nameSheet = ThisWorkbook.Sheets("DATA").Range("A" & lastLine)
nok = feuilleExiste(nameSheet)
If nok = True Then
MsgBox " Cette feuille existe déjà"
Else
ThisWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count())
ThisWorkbook.Sheets(Worksheets.Count()).Name = nameSheet
ThisWorkbook.Sheets("TTC").UsedRange.Copy Destination:=ThisWorkbook.Sheets(nameSheet).Range("A1")
ThisWorkbook.Sheets("DATA").Activate
End If
End Sub
Function feuilleExiste(FeuilleAVerifier As String) As Boolean
'fonction qui vérifie si la "FeuilleAVerifier" existe dans le Classeur actif
On Error Resume Next
ThisWorkbook.Sheets(FeuilleAVerifier).Name = Sheets(FeuilleAVerifier).Name
feuilleExiste = (Err.Number = 0)
End Function