Hi All,
The below code was picked up from this forum and one of this forum members has helped in copying the Value and Format and placing it in the new sheet.
I am trying to select a sheet to be copied via macro which is not working. I am absolutely new to coding and request the team to excuse me if there is a silly coding mistake.
Below is the objective:
The macro should give a dialogue box to select the Input Sheet to be copied rather than explicitly specifying "Sheet Name" in the code
Best Regards,
Srikanth
Option Explicit
Dim sName As String
Dim sPic As String
sPic = Application.InputBox("Enter the Sheet To be Copied:", Title:="Source Sheet Title", Type:=2)
If sPic = "" Then Exit Sub
Dim v: v = Evaluate("ISREF(sPic!A1)")
If v Then
sName = Application.InputBox("Enter the new sheet name:", Title:="New Sheet Title", Type:=2)
If sName = "" Then Exit Sub
Sheets("sPic").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = sName
Else
MsgBox "The ""sPic"" cannot be found."
End If
End Sub
Would like to implement the above in the below code:
Option Explicit
Sub NewSheetFromTemplate()
Dim sName As String
sName = Application.InputBox("Enter the new sheet name:", Title:="New Sheet Title", Type:=2)
If sName = "" Then Exit Sub
ActiveWorkbook.Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = sName
Sheets("Template").Cells.Copy
With Sheets(sName).Range("A1")
.PasteSpecial xlValues
.PasteSpecial xlFormats
.PasteSpecial xlPasteValidation
End With
End Sub
Bookmarks