Results 1 to 5 of 5

Create new worksheets, name, and link

Threaded View

  1. #1
    Registered User
    Join Date
    05-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    14

    Create new worksheets, name, and link

    I don't know anything about writing in VB, I tried to record my macro, but it's not working right for me. So, now I'm trying to tweak the code, but need some help.

    I started a workbook to keep all of the information for each of our direct brokerage cases. The idea is to have a worksheet for each group, and a table of contents with hyperlinks to each page. Also on the table of contents I’m trying to pull in some specific fields from the group’s worksheet (renewal dates).

    I have a template page built. I want my macro to copy and rename the template page for each new group, then to add formulas to the table of contents that pulls information from the group's worksheet.

    The first problem I encountered was:
    My macro works the first time I use it, then when I try to add a second group it, instead of adding the information to a new line, it overwrites my first line.

    Then I searched the internet for some formulas (shown below in red) to find the next free row, but now every time it starts one row down, it’s also pulling the data from the other tab one cell down…. I tried recording the macro using the Absolute Cells (Example $A$1), but that’s not working.

    This is one way to get the next free row, assuming column B here
    cLastRow = Cells(Rows.Count,"B").end(xlUp).Row+1
    to access that cell, use
    Cells(cLastRow,"B").Value = ....


    See attached image of what results I'm getting vs. what I need to happen
    Excel.JPG



    Sub New_Group_Setup()
    '
    ' New_Group_Setup Macro
    ' Macro recorded 5/15/2012 by Kristin_Stout
    '
    ' Keyboard Shortcut: Ctrl+Shift+N
    '
        Sheets("Template").Select
        Sheets("Template").Copy Before:=Sheets(2)
        Sheets("Template (2)").Select
        Sheets("Template (2)").Name = "New Group"
        Sheets("Direct Cases Listing").Select
        Selection.End(xlDown).Select
        cLastRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
        Cells(cLastRow, "A").Value = "New Group"
        ActiveCell.FormulaR1C1 = "New Group"
        cLastRow = Cells(Rows.Count, "B").End(xlUp).Row + 1
        Cells(cLastRow, "B").Value = "='New Group'!R[-4]C[8]"
        cLastRow = Cells(Rows.Count, "C").End(xlUp).Row + 1
        Cells(cLastRow, "C").Value = "='New Group'!R[5]C[2]"
        cLastRow = Cells(Rows.Count, "D").End(xlUp).Row + 1
        Cells(cLastRow, "D").Value = "='New Group'!R[6]C[1]"
        cLastRow = Cells(Rows.Count, "E").End(xlUp).Row + 1
        Cells(cLastRow, "E").Value = "='New Group'!R[7]C"
        cLastRow = Cells(Rows.Count, "F").End(xlUp).Row + 1
        Cells(cLastRow, "F").Value = "='New Group'!R[8]C[-1]"
        cLastRow = Cells(Rows.Count, "G").End(xlUp).Row + 1
        Cells(cLastRow, "G").Value = "='New Group'!R[9]C[-2]"
        cLastRow = Cells(Rows.Count, "H").End(xlUp).Row + 1
        Cells(cLastRow, "H").Value = "='New Group'!R[10]C[-3]"
        Range("A3").Select
        Sheets("New Group").Select
    End Sub
    I think I spent way too much time on this, and maybe the solution is simple. Please let me know if you can help, or have any questions about what I’m trying to do. Thank you so much!!

    Attached is the excel document. When you open it, press Ctrl+Shirt+N to run the macro (the first one works), then rename the “New Group” tab to something else, and run the macro again, and you’ll be able to see the problem.
    Attached Files Attached Files
    Last edited by arlu1201; 05-18-2012 at 11:05 AM. Reason: Edited thread title for user.

Thread Information

Users Browsing this Thread

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

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