Results 1 to 2 of 2

Thread: Excel VBA Code to Add New Sheets

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    21
    Rep Power
    0

    Excel VBA Code to Add New Sheets

    I am completely green to VBA and need to get an excel spreadsheet to create a new workbook when I press a button. I do not know anything on how to do this so any help will be greatly appreciated.

    I want to push a button and have the macro run.

    I want to have the following happen:

    If there is a future date in any of the following cells R, V, AA, AF, AH, AK, AP, or AU I want it to copy the following
    for all I need C, K, L, M, M, O, P, Q, R to copy over and then if R if it is a future date, V and X if V is a future date, AA and AC, if AA is future, and so on except AU only if AU is future date.

    I would then like it to ask me if I want to email the new workbook. If yes to email to a distribution list and if no to end.

    the original spreadsheet is called "CPC" and I want the new workbook to be called "CPC Schedule"

    Can anyone help me????

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    The VBA code to add a new sheet is

    Code:
    Sub CustomAddSheet()
        
        'ActiveWorkbook can be replaced with any specific workbook object like: ThisWorkbook, Workbooks("NameOfFile.xls") etc
        With ActiveWorkbook
            .Sheets.Add .Sheets(1), , 2, xlChart
        End With
        
    End Sub
    The arguments are [Before], [After], [Count], [Type]

    In the code above, I put the .Sheets(1) as the [Before] argument. You could have also done that using it as the [After] argument. Of course the differences are obvious.

    [Count] gives you the option to put the number of sheets to be added. and [Type] gives you the option to add the type of sheet. This could be either xlWorksheet, xlChart or even a few others.

    Now, I understand this is not your only requirement, and it just forms a minor portion of what you're asking for. If you've got all that covered, good. Else, feel free to post back (since this is anyway a delayed post)
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. VBA Code To Email Multiple Recipients From Excel
    By cdurfey in forum Excel Help
    Replies: 4
    Last Post: 06-11-2013, 12:18 AM
  2. Add VBA Reference From Another Application Excel To PowerPoint
    By ds1001 in forum Rajan Verma's Corner
    Replies: 1
    Last Post: 06-02-2013, 02:43 PM
  3. Using excel solver add-in.
    By Safal Shrestha in forum Excel Help
    Replies: 0
    Last Post: 05-09-2013, 12:07 PM
  4. Replies: 17
    Last Post: 12-18-2012, 04:15 PM
  5. Add ribbon programmatically to Excel 2010 using VBA
    By heapifyman in forum Excel Ribbon and Add-Ins
    Replies: 6
    Last Post: 07-18-2011, 09:16 PM

Posting Permissions

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