Results 1 to 9 of 9

To select an Input Sheet to Copy

Threaded View

  1. #1
    Registered User
    Join Date
    08-11-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    58

    To select an Input Sheet to Copy

    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
    Last edited by sreeks; 08-28-2010 at 03:35 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1