Solved

Copy worksheet without references or formulas

Posted on 2015-01-19
7
86 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 6

Assisted Solution

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

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 6

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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Closing Comment

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

Expert Comment

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

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 6

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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