+ Reply to Thread
Results 1 to 6 of 6

Insert Copied sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    10-10-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    4

    Smile Insert Copied sheet

    Hi there,
    I'm a newbe in excel programming and hope to get some help in this forum.
    I'm trying to make a workbook, where each sheet are testequipment records.
    Did find some codes but they need som minor rewriting.

    I would like the "insert serial" macro to copy the "new sheet" instead of inserting a empty sheet after the "master"
    (and still rename the copied sheet with value from inputbox")

    Regarding the "search serial" macro, could this return a message if serial not found. like serial not found, would you insert a new one. (yes-No)

  2. #2
    Registered User
    Join Date
    10-10-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    4

    Cool Re: Insert Copied sheet

    Sorry, forgot to upload the workbook....here it is
    Attached Files Attached Files

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Insert Copied sheet

    For your first question replace the similar code (module 9) with this new code:

    Public Sub AddSheet()
    Dim shName As String, newsht As String
    Dim shExists As Boolean
    
    Do
    
    shName = InputBox("Please Enter the Item Serial number")
    If shName <> "" Then
    
    shExists = SheetExists(shName)
    If Not shExists Then
    
    newsht = Sheets("new sheet").Copy(after:=Worksheets(Worksheets.Count))
    Sheets(Worksheets.Count).Name = shName
    
    Else
    
    MsgBox "Worksheet " & shName & " already exists", vbOKOnly + vbInformation, "Add Sheet"
    End If
    End If
    Loop Until Not shExists Or shName = ""
    End Sub
    For your second question replace the similar code (module 2) with:

    Sub GotoSheet()
      
      ' Jumping between Worksheets
        Dim sSheet As String
        sSheet = InputBox( _
        Prompt:="Serial number?", _
          Title:="Serial Search Box")
        On Error Resume Next
        If sSheet = vbCancel Then Exit Sub
        If Val(sSheet) > 9999999999999# Then
            Worksheets(Val(sSheet)).Activate
        Else
            msg = MsgBox("Serial not found, would you like to enter a new one?", vbYesNo)
                If msg = vbYes Then
                    Call GotoSheet
                    Exit Sub
                End If
            Worksheets(sSheet).Activate
        End If
    End Sub
    Last edited by stnkynts; 10-12-2012 at 05:58 PM. Reason: edited to add yes/no box that OP requested

  4. #4
    Registered User
    Join Date
    10-10-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Insert Copied sheet

    Hi stnkynts,
    First of all ... THANKS... the first one (module 9) .... excellent, works nice. Question, could i hide the "new sheet" and have the new copied one, visible?

    In module 2, the message box pops up even if the serialnumber i'm searching for is already inserted, If i answer "No" the message box disappears and cursor then jumps to the correct sheet, if the sheet is named with letters then nothing happends !!!

    regards
    sikke

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Insert Copied sheet

    Sorry about the confusion. Try these in module 9 and 2 respectively:

    Public Sub AddSheet()
    Dim shName As String, newsht As String
    Dim shExists As Boolean
    
    Application.ScreenUpdating = False
    Sheets("new sheet").Visible = True
    Do
    
    shName = InputBox("Please Enter the Item Serial number")
    If shName <> "" Then
    
    shExists = SheetExists(shName)
    If Not shExists Then
    
    newsht = Sheets("new sheet").Copy(after:=Worksheets(Worksheets.Count))
    Sheets(Worksheets.Count).Name = shName
    Sheets("new sheet").Visible = False
    Sheets(shName).Activate
    
    Else
    
    MsgBox "Worksheet " & shName & " already exists", vbOKOnly + vbInformation, "Add Sheet"
    End If
    End If
    Loop Until Not shExists Or shName = ""
    Application.ScreenUpdating = True
    End Sub
    Sub GotoSheet()
      
      ' Jumping between Worksheets
        Dim sSheet As String
        Dim wksht As Worksheet
        Dim msg
        sSheet = InputBox( _
        Prompt:="Serial number?", _
          Title:="Serial Search Box")
        On Error Resume Next
        If sSheet = vbCancel Then Exit Sub
        For Each wksht In Application.Worksheets
            If wksht.Name = sSheet Then
                wksht.Activate
                Exit Sub
            End If
        Next wksht
            msg = MsgBox("Serial not found, would you like to enter a new one?", vbYesNo)
                If msg = vbYes Then
                    Call GotoSheet
                    Exit Sub
                End If
    End Sub

  6. #6
    Registered User
    Join Date
    10-10-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Insert Copied sheet

    Hi again,
    Regarding module 2, When i'm searching for a serial no. where the name starts with a letter, nothing happends. Any clue

    regards
    Sikke

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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