Solved

Copy a worksheet & rename from cell value

Posted on 2015-01-17
6
77 Views
Last Modified: 2015-01-19
Hello Experts,

I'd like a macro to:
1)  copy the current worksheet to the end of the workbook  (number of worksheets is variable)
2a) Use the name from N1:T1 cell (a merged field) to rename the worksheet
2b) if the worksheet name is already used, append 1 or 2 or 3 etc.

A sample file is attached.

Thanks
InfoBook.xlsx
0
Comment
Question by:bikeski
  • 3
  • 3
6 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40555892
You can use this macro.

Sub AddSheet()

    Dim lngSheets As Long
    Dim intCount As Integer
    
    ActiveSheet.Copy After:=Sheets(Sheets.Count)
    
    For lngSheets = 1 To Sheets.Count
        If Left$(Sheets(lngSheets).Name, Len(Range("N1"))) = Range("N1") Then
            intCount = intCount + 1
        End If
    Next
    If intCount > 0 Then
        ActiveSheet.Name = Range("N1") & intCount
    Else
        ActiveSheet.Name = Range("N1")
    End If
       
End Sub

Open in new window

0
 

Author Closing Comment

by:bikeski
ID: 40558551
Thanks Martin, works great!
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40558580
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:bikeski
ID: 40558656
Martin, You did as I asked. After applying the macro to several worksheets, I realized I needed to copy everything except the formulas, there I only want the numbers. Let me know how you'd like to proceed, I can open a new question?
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40558678
Sure. Let me know when you've added the question.
0
 

Author Comment

by:bikeski
ID: 40558824
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now