View Single Post
 
Old 01-05-2017, 11:51 AM
cloudforgiven cloudforgiven is offline Windows XP Office 2013
Novice
 
Join Date: Nov 2016
Posts: 13
cloudforgiven is on a distinguished road
Default

Ah you can just add a second sheet, also there will never be anything on the new sheet I am pasting to because I have a button that ask the user what they want the new sheet name to be and then generates the NEW sheet named after what the user inputted. However I also want the new sheet that is being generated to have the table you see in the attachment, so Ill just add the code(To copy and paste that SHEET which has the table) to whatever I already have which is :

Code:
Function SheetExists(shtName As String, Optional wb As Workbook) As Boolean
    Dim sht As Worksheet

     If wb Is Nothing Then Set wb = ThisWorkbook
     On Error Resume Next
     Set sht = wb.Sheets(shtName)
     On Error GoTo 0
     SheetExists = Not sht Is Nothing
 End Function
 

Private Sub CommandButton2_Click()

Dim SheetName As String
Dim shExists As Boolean

Do

SheetName = InputBox("Please enter the LAST NAME of the DTS.", "Add Sheet")
If SheetName <> "" Then
shExists = SheetExists(SheetName)
    If Not shExists Then
        Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = SheetName
        MsgBox "The " & (SheetName) & " sheet was successfuly made. Please don't forget to CHANGE the name under the field DTS NAME.", , "Result"
    Else
        MsgBox "The last name already exists, please enter a NUMBER at the end of the LAST NAME to distinguish it from the existing one. For example lastname1 or lastname2", vbOKOnly + vbInformation, "Name"
    End If
Else
    MsgBox "You did not enter anything.", vbOKOnly + vbInformation, "Warning"

'Exit Function
End If
End Sub
Reply With Quote