Hi.I have this code to copy a specific sheet provided that the number of values in the H column and rename it with the same value, but it is very slow because I have to scrape all the sheets and recreate them again, which is about 400 sheets, is there a way to check the existence of the sheet name, override it, and copy the rest to be faster, or any other way.
VBA Code:
Sub TEST()
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
On Error GoTo Errorhandling
Set ST = Sheet1
lr = ST.Range("h" & Rows.Count).End(xlUp).Row
Sheet2.Visible = True
Set rng = Range("H2:H" & lr)
Application.ScreenUpdating = True
For Each ws In Worksheets
If ws.Name <> ("Vehicle") And ws.Name <> ("Data") And ws.Name <> ("Sample") Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
Next
For Each cell In rng
If cell <> "" Then
Worksheets("Sample").Copy After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = cell
Range("i19").Value = ActiveSheet.Name
Sheet2.Visible = False
End If
Next cell
Errorhandling:
Sheet1.Activate
Sheet1.Range("b2:b" & lr).ClearContents
Sheet1.Range("b2").Select
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> ("Vehicle") And ws.Name <> ("Data") And ws.Name <> ("Sample") Then
ActiveCell.Hyperlinks.Add Anchor:=ActiveCell, Address:="", SubAddress:="" & ws.Name & "!A1" & "", ScreenTip:="", TextToDisplay:=ws.Name
ActiveCell.Offset(1, 0).Select
Application.ScreenUpdating = False
End If
Next ws
End Sub