+ Reply to Thread
Results 1 to 2 of 2

How to force macro to skip cell data if the sheet name is already used.

Hybrid View

  1. #1
    Registered User
    Join Date
    08-10-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    11

    How to force macro to skip cell data if the sheet name is already used.

    Here is my macro. As of now it creates new sheets based off of names in cells then moves down one. I want to be able to later on add another name to the list and run the macro again, skipping the cells that I have already used. Is this possible?

    Sub test()
             
            
             Worksheets("Associate DOH").Select
             Range("E2").Select
             
                     
             'This tells the macro to stop the loop when a blank cell is found
        Do Until (ActiveCell.Value) = ""
                          
                          
             'This takes the contents of the selected cell and prepares it to be a new sheet name.
             newname = ActiveCell.Value
             
        
             
        
                      
             'This selects the qees eval sheet and copies it.
             Sheets("QEES Eval").Select
             Range("A1:J46").Select
             Selection.Copy
             
             
             'This adds one sheet to the workbook and selects cell A1.
             Sheets.Add After:=Sheets(Sheets.Count)
             Range("A1").Select
             
             
             'This paste the contents earlier selected into the new sheet.
             Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
             SkipBlanks:=False, Transpose:=False
             Cells.Select
             ActiveSheet.Paste
             
             
             'This assigns to new sheet the new name.
             ActiveSheet.Name = newname
                      
                      
             'This returns back to the first worksheet.
             Worksheets("Associate DOH").Select
                      
                      
             'This moves the selection of the cell down one row.
             ActiveCell.Offset(1, 0).Select
          
                      
          Loop
       End Sub
    Last edited by Cutter; 08-18-2012 at 06:58 PM. Reason: Added code tags

  2. #2
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: How to force macro to skip cell data if the sheet name is already used.

    @ cody4334

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at top of the page and read Rule #3.
    Thanks.

+ Reply to Thread

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