Results 1 to 3 of 3

create new workbook, copy data, rename sheet.

Threaded View

simeonmein create new workbook, copy... 10-09-2013, 02:52 PM
patel45 Re: create new workbook, copy... 10-10-2013, 01:52 AM
HaHoBe Re: create new workbook, copy... 10-10-2013, 02:00 AM
  1. #1
    Registered User
    Join Date
    09-11-2013
    Location
    zastron,south africa
    MS-Off Ver
    Excel 2010
    Posts
    48

    create new workbook, copy data, rename sheet.

    Hi all
    My aim is to click a commandbutton in a userform with 4 textboxes.
    Then a new workbook must be created, the data must be pasted and the sheet must be named after textbox2. After this the sheet must contain the values of the userform textboxes values, then it must save the workbook and name it from textbox1 or activesheet range for textbox1.

    This is my current code:

    Private Sub CommandButton1_Click()
    
        Dim ws As Worksheet, i As Long, lRow As Long, FName As String, FPath As String, NewBook As Workbook
        FPath = "c:\pos"
        FName = "sup" & TextBox1.Value
            Set ws = Sheets("supdata")
            Set NewBook = Workbooks.add
            ThisWorkbook.Sheets("supdata").Copy before:=NewBook.Sheets(1)
        If Dir(FPath & "\" & FName) <> "" Then
            MsgBox "file " & FPath & "\" & FName & " exists"
    
        End If
         
                
          '____error handling______
    
    
    If TextBox1.Value = "" Or nullstring Then
    MsgBox "Complete All Information!", vbCritical, "Error..."
    GoTo error1
    End If
          
          
          
          '____error handling end______
       
        If MsgBox("Add " & TextBox1.Value & " to the database?", vbYesNo, "Confirm add") = vbYes Then
       
          NewBook.Cells(lRow, "A") = TextBox1.Value
          NewBook.Cells(lRow, "B") = TextBox2.Value
          NewBook.Cells(lRow, "C") = TextBox3.Value
          NewBook.Cells(lRow, "D") = TextBox4.Value
          
        
        MsgBox TextBox1.Value & " has been added "
        
        TextBox1.Value = nullstring
        TextBox2.Value = nullstring
        TextBox3.Value = nullstring
        TextBox4.Value = nullstring
        
        NEWACC.Hide
        
            
        Else
        End If
        
    
        
        ADDSTOCK.Show vbModeless
        
    error1:
    End Sub
    Any help will be appriciated, thanx
    Last edited by arlu1201; 10-10-2013 at 01:01 AM. Reason: Corrected code tags.
    Creating POS

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] A button to create Sheet2, copy there data from Sheet1 and rename the sheet?
    By mintymike in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-17-2012, 10:34 AM
  2. Replies: 2
    Last Post: 09-04-2012, 01:19 AM
  3. [SOLVED] Code to create new sheet and rename, regardless of any other sheets in workbook
    By csh8428 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-19-2012, 02:22 PM
  4. Replies: 0
    Last Post: 04-28-2012, 06:06 PM
  5. Create copy of sheet & rename
    By Vetequk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2010, 08:40 AM

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