Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy worksheet without references or formulas

Posted on 2015-01-19
7
Medium Priority
?
90 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 6

Assisted Solution

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

Accepted Solution

by:
Martin Liss earned 1600 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 49

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

715 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