Solved

Copy worksheet without references or formulas

Posted on 2015-01-19
7
83 Views
Last Modified: 2015-01-19
Hello Experts,

The following code copies a worksheet which works. However, I need to copy the worksheet with the formatting, graphs, etc but without any formulas or references to other worksheets.

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
0
Comment
Question by:bikeski
  • 4
  • 2
7 Comments
 
LVL 5

Assisted Solution

by:Flora
Flora earned 100 total points
ID: 40558828
add this line ActiveSheet.UsedRange.Value = ActiveSheet.UsedRange.Value
0
 
LVL 45

Accepted Solution

by:
Martin Liss earned 400 total points
ID: 40558920
Sub AddSheet()

    Dim lngSheets As Long
    Dim intCount As Integer
    
    ActiveSheet.Copy After:=Sheets(Sheets.Count)
    
    With ActiveSheet.UsedRange
        .Value = .Value
    End With
    
    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
 
LVL 5

Expert Comment

by:Flora
ID: 40558922
Hi Martin.

 that this exactly as I suggested. you did the shortcut using "With"

:-)

anyways, I am your pupil
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Closing Comment

by:bikeski
ID: 40558934
Thanks, that worked. I gave Martin more points as he provided the full code;)
0
 
LVL 5

Expert Comment

by:Flora
ID: 40558935
not fair :)
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40558986
Flora, my code did use With, but more importantly it showed the author where to add the new code. In any case if you really don't think the current split is fair I'm happy to split the points with you 50/50. Just Request attention.
0
 
LVL 5

Expert Comment

by:Flora
ID: 40558991
Martin,
no worries, of course I was just messing/joking with you :-)  
points are not important, what is important is that author got his answer and everyone is happy, including me :-)

thank you for being so generous and so nice.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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 Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
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.

747 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

14 Experts available now in Live!

Get 1:1 Help Now