+ Reply to Thread
Results 1 to 11 of 11

Creating new tabs based on cell values

  1. #1
    Registered User
    Join Date
    02-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    31

    Creating new tabs based on cell values

    Hello people of the Excel Help Forum.

    I'm a new member and this problem is one of the main factors for my membership.

    I am trying to write a macro, but running into some difficulty. I have an excel workbook that contains one sheet, “Labor,” with the following information.
    A B C D E F G H
    1 Order No., Cost Elem, Cost Elem Name, ID Number, Cost Center, Amount, Quantity, and Posting Date
    2 333458312 ... ... SAL-MGMT S/T ... ... ... ...
    3 333458312 ... ... SAL-UNION S/T ... ... ... ...
    4 333458312 ... ... EMP TRVL-MEALS/ENT... ... ... ...

    and so on. I am going to run this macro on multiple spreadsheets (but only one at a time). They all have 8 columns, but the numbers of rows vary (aka dynamic range). The column I care about is C (Cost Element Name). I want to make a new tab for all of the different labor types.
    There are several cost element names, but I only care about 5 of them. They are: “SAL-MGMT S/T”, “SAL-CLERICAL/TECH ST”, “SAL-UNION S/T”, “SAL-TEMP P-T S/T”, and “SRV-TEMP AGNCY LABOR.” The five cost element names fall into 4 different categories: MGMT Labor, CT Labor (contains CLERICAL/TECH labor and TEMP P-T), Union Labor, and Agency Labor. I want the new spreadsheets in the same workbook and named after the four categories. So all the Union labor would be in the “Union Labor” sheet along with all the information in their row. Also, if the Cost Element Name does not fall under one of the five names I want, I want that row deleted (My example row #4 would be deleted since the cost element name is EMP TRVL-MEALS/ENT.)

    I’ve tried adapting the code from the answer to this question (http://www.computing.net/answers/off...ets/13596.html), but I keep getting this error, “Runtime '1004' application-defined or object-defined error” for the line that reads ActiveSheet.Name = rateName.

    Here is my code:
    Please Login or Register  to view this content.
    Last edited by Airgaf; 02-23-2011 at 08:04 PM.

  2. #2
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Creating new tabs based on cell values

    Hi,

    Welcome to the forum.
    Can you post a copy of your workbook.
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  3. #3
    Registered User
    Join Date
    02-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Creating new tabs based on cell values

    Sure. Here is the workbook.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Creating new tabs based on cell values

    HI,

    Too let you know that you can not as far as I know create a New worksheet that contains
    "Spaces, "/"". is there another way you want to name the sheets.
    It seem you can not use "/" as part of the sheet name.
    Last edited by Charles; 02-23-2011 at 06:18 PM. Reason: edit info

  5. #5
    Registered User
    Join Date
    02-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Creating new tabs based on cell values

    Thank you so much Charles!

  6. #6
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Creating new tabs based on cell values

    Airgaf,

    I'm coding to change the "/" to "-"
    If that's ok.

  7. #7
    Registered User
    Join Date
    02-23-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Creating new tabs based on cell values

    Lol, that's what I did.

    Application.FindFormat.NumberFormat = "@"
    Cells.Replace What:="/", Replacement:="-", LookAt:=xlPart, SearchOrder _
    :=xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=False

  8. #8
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Creating new tabs based on cell values

    Hi,

    You show this as "Solved" but here's my code.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-14-2011
    Location
    Switzerland
    MS-Off Ver
    MacOffice 2011, Excel
    Posts
    17

    Re: Creating new tabs based on cell values

    This macro is great!!! Thank you so much for sharing this!!!!!!
    Is there any possibility that the macro does not overwrite existing sheets, but creates new ones?
    For example my excel file has already 5 sheets. when I run the code for sheet 1, sheet 2, 3 etc are overwritten with the new results, is it possible that the create new sheets beginning from sheet 6...
    Thank you!

  10. #10
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Creating new tabs based on cell values

    med1234,

    Welcome to the forum. Please start your own thread for this request.

  11. #11
    Registered User
    Join Date
    08-14-2011
    Location
    Switzerland
    MS-Off Ver
    MacOffice 2011, Excel
    Posts
    17

    Re: Creating new tabs based on cell values

    Thank you! I have now created a new forum posting regarding this issue... Perhaps people working with this code could also comment there...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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