+ Reply to Thread
Results 1 to 15 of 15

create new sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-13-2013
    Location
    Swindon UK
    MS-Off Ver
    Excel 2010
    Posts
    287

    create new sheet

    HI
    Hope i explain this correct.

    I have a macro that will look in a folder for a name based on cell info in(E8) ie name of smith. when it fines the file it opens up . all works ok.


    But what i want to do is , if the file name dont excist i want it open a blank template called "Blank" and save the file name based on the name in (E8)

    this is the code i use at the moment

    Workbooks.Open Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & Range("e8") & ".xlsm"

  2. #2
    Forum Contributor
    Join Date
    06-02-2015
    Location
    delhi
    MS-Off Ver
    2010
    Posts
    104

    Re: create new sheet

    Sub T()
    Set wb1 = ActiveWorkbook
    On Error Resume Next
    Workbooks.Open Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & Range("e8") & ".xlsm"
    Set wb = Workbooks.Add
    MsgBox wb1.Sheets("Sheet1").Range("e8")
    wb.SaveAs Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & wb1.Sheets("Sheet1").Range("e8"), FileFormat:=52
    End Sub

  3. #3
    Forum Contributor
    Join Date
    05-13-2013
    Location
    Swindon UK
    MS-Off Ver
    Excel 2010
    Posts
    287

    Re: create new sheet

    HI

    Thank you for the code. but it only opens a blank page.

    I want it to open a blank template in Workbooks.Open Filename:="S:\Administration\Administration\000 Taxi Requests 000\ 000 balnk 000

  4. #4
    Forum Contributor
    Join Date
    05-13-2013
    Location
    Swindon UK
    MS-Off Ver
    Excel 2010
    Posts
    287

    Re: create new sheet

    HI

    This is what i have used, but if it dont find the file name it still eorrors out . i want it to open the next file on error

    Sub Taxi2()
        Workbooks.Open Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & Range("e8") & ".xlsm"
        On Error Resume Next
    
    
    Workbooks.Open Filename:="S:\Administration\Administration\000 Taxi Requests 000\000 Blank 000.xlsm"

  5. #5
    Valued Forum Contributor meabrams's Avatar
    Join Date
    10-03-2014
    Location
    USA
    MS-Off Ver
    2007, 2010, 2013, 2016
    Posts
    451

    Re: create new sheet

    you could try but your going to need the full file name to have to work proper.
    Sub Test()
    On Error GoTo Error1
    Workbooks.Open Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & Range("e8") & ".xlsm"
    Exit Sub
    Error1:
    Set wb1 = ActiveWorkbook
    Set wb = Workbooks.Open (Filename:="S:\Administration\Administration\000 Taxi Requests 000\ 000 balnk 000")
    wb.SaveAs Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & wb1.Sheets("Sheet1").Range("e8"), FileFormat:=52
    End Sub

  6. #6
    Forum Contributor
    Join Date
    05-13-2013
    Location
    Swindon UK
    MS-Off Ver
    Excel 2010
    Posts
    287

    Re: create new sheet

    Hi

    Thank you the code works but it fails to save the file it gets stuck on that line of code

  7. #7
    Forum Contributor
    Join Date
    06-02-2015
    Location
    delhi
    MS-Off Ver
    2010
    Posts
    104

    Re: create new sheet

    What is the error there ???

  8. #8
    Forum Contributor
    Join Date
    05-13-2013
    Location
    Swindon UK
    MS-Off Ver
    Excel 2010
    Posts
    287

    Re: create new sheet

    I get a box pop up saying

    Run time error '9'
    subscript out of range.

    then it higlights the line

    wb.SaveAs Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & wb1.Sheets("Sheet1").Range("e8"), FileFormat:=52

  9. #9
    Forum Contributor
    Join Date
    06-02-2015
    Location
    delhi
    MS-Off Ver
    2010
    Posts
    104

    Re: create new sheet

    You have changed my code at workbook add method to open method try this again !! Make sure E8 contains some valid name value so that file can be saved without error.


    Sub Test()
    On Error GoTo Error1
    Workbooks.Open Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & Range("e8") & ".xlsm"
    Exit Sub
    Error1:
    Set wb1 = ActiveWorkbook
    Set wb = Workbooks.Add
    wb.SaveAs Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & wb1.Sheets("Sheet1").Range("e8"), FileFormat:=52
    End Sub

  10. #10
    Forum Contributor
    Join Date
    05-13-2013
    Location
    Swindon UK
    MS-Off Ver
    Excel 2010
    Posts
    287

    Re: create new sheet

    HI its ok i found the problem.

    it's sheet 4 and not sheet1.

    Thnk you for your help

  11. #11
    Forum Contributor
    Join Date
    06-02-2015
    Location
    delhi
    MS-Off Ver
    2010
    Posts
    104

    Re: create new sheet

    Haha M going to Suicide !! glad to help

  12. #12
    Forum Contributor
    Join Date
    05-13-2013
    Location
    Swindon UK
    MS-Off Ver
    Excel 2010
    Posts
    287

    Re: create new sheet

    Oh sorry a small problem

    if the file dont excist it creats a new one which is what i want but

    if the file dose excist it opens it up and also creates a new one. i i have 2 folder opens with the same name ??

  13. #13
    Forum Contributor
    Join Date
    05-13-2013
    Location
    Swindon UK
    MS-Off Ver
    Excel 2010
    Posts
    287

    Re: create new sheet

    Here is the code im using

    Sub Test()
    On Error GoTo Error1
    Workbooks.Open Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & Range("e8") & ".xlsm"
    
    Error1:
    Set wb1 = ActiveWorkbook
    Set wb = Workbooks.Open(Filename:="S:\Administration\Administration\000 Taxi Requests 000\Blank.xlsm")
    Sheets(1).Range("d12").Value = ThisWorkbook.Sheets(1).Range("b8").Value & " " & ThisWorkbook.Sheets(1).Range("e8").Value
    wb.SaveAs Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & wb1.Sheets("Sheet4").Range("e8") & ".xlsm"

  14. #14
    Forum Contributor
    Join Date
    06-02-2015
    Location
    delhi
    MS-Off Ver
    2010
    Posts
    104

    Re: create new sheet

    Sub Test()
    On Error GoTo Error1
    Workbooks.Open Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & Range("e8") & ".xlsm"
    exit sub
    Error1:
    Set wb1 = ActiveWorkbook
    Set wb = Workbooks.Open(Filename:="S:\Administration\Administration\000 Taxi Requests 000\Blank.xlsm")
    Sheets(1).Range("d12").Value = ThisWorkbook.Sheets(1).Range("b8").Value & " " & ThisWorkbook.Sheets(1).Range("e8").Value
    wb.SaveAs Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & wb1.Sheets("Sheet4").Range("e8") & ".xlsm"

  15. #15
    Forum Contributor
    Join Date
    05-13-2013
    Location
    Swindon UK
    MS-Off Ver
    Excel 2010
    Posts
    287

    Re: create new sheet

    HI

    Thank you

    After using your code it dont copy the data from the sheet from my code. here is the full code. when it opens the new page its just blank with no data

    Sub Test()
    On Error GoTo Error1
    Workbooks.Open Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & Range("e8") & ".xlsm"
    Exit Sub
    Error1:
    Set wb1 = ActiveWorkbook
    Set wb = Workbooks.Open(Filename:="S:\Administration\Administration\000 Taxi Requests 000\Blank.xlsm")
    Sheets(1).Range("d12").Value = ThisWorkbook.Sheets(1).Range("b8").Value & " " & ThisWorkbook.Sheets(1).Range("e8").Value
    wb.SaveAs Filename:="S:\Administration\Administration\000 Taxi Requests 000\" & wb1.Sheets("Sheet4").Range("e8") & ".xlsm"
    
    
    
        Sheets(1).Range("d13").Value = ThisWorkbook.Sheets(1).Range("j8").Value
        Sheets(1).Range("d14").Value = ThisWorkbook.Sheets(1).Range("b9").Value & " " & ThisWorkbook.Sheets(1).Range("e9").Value
        Sheets(1).Range("d15").Value = ThisWorkbook.Sheets(1).Range("j9").Value
        Sheets(1).Range("d16").Value = ThisWorkbook.Sheets(1).Range("b10").Value & " " & ThisWorkbook.Sheets(1).Range("e10").Value
        Sheets(1).Range("d17").Value = ThisWorkbook.Sheets(1).Range("j10").Value
        Sheets(1).Range("d18").Value = ThisWorkbook.Sheets(1).Range("b11").Value & " " & ThisWorkbook.Sheets(1).Range("e11").Value
        Sheets(1).Range("d19").Value = ThisWorkbook.Sheets(1).Range("j11").Value
        Sheets(1).Range("d20").Value = ThisWorkbook.Sheets(1).Range("b12").Value & " " & ThisWorkbook.Sheets(1).Range("e12").Value
        Sheets(1).Range("d21").Value = ThisWorkbook.Sheets(1).Range("j12").Value
        Sheets(1).Range("r4").Value = ThisWorkbook.Sheets(1).Range("p8").Value & " " & ThisWorkbook.Sheets(1).Range("k8").Value
        Sheets(1).Range("o11").Value = ThisWorkbook.Sheets(1).Range("b33").Value
        Sheets(1).Range("m12").Value = ThisWorkbook.Sheets(1).Range("e33").Value
        Sheets(1).Range("ab11").Value = ThisWorkbook.Sheets(1).Range("b35").Value
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VBA Help needed to create sheet based on master sheet column cell values
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-12-2016, 04:58 PM
  2. How to create a macro to create a pivot table on a new sheet
    By thlee1122 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-19-2015, 11:14 AM
  3. [SOLVED] Macros to Create New Sheet, Rename, and Create HyperLink to New Worksheet
    By jacksum in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-19-2015, 12:44 PM
  4. Create button when clicking create new sheet with changing name
    By damaple in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-04-2013, 04:56 AM
  5. Copy Sheet / Create & Name New Sheet / Insert Before a Sheet / Paste Data
    By thinkspac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2012, 02:27 PM
  6. Copy Sheet & Create New Monthly Sheet From Present Sheet
    By unley in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2010, 12:00 PM
  7. Need to create a button that can copy cells, create a new sheet and then paste there
    By torontoguy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-14-2009, 11:26 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