Solved

How do I copy data from a worksheet to a Summary listing on another worksheet?

Posted on 2015-02-07
2
95 Views
Last Modified: 2016-02-10
Hello Experts,

This is a continuation of http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28588137.html and the updated code is below.

In addition to copying the worksheets, I'd like to copy parameters from the "Calc" worksheet to a "Summary" worksheet. The Summary worksheet has 7 columns and the copied info needs to be added to the bottom of the list. Here's the mapping from the Calc worksheet to the Summary worksheet:

Calc:P1 -> column 1
Calc:P3 -> column 2
Calc:X71 -> column 3
Calc:x73 -> column 4
Calc:W67 -> column 5
Calc:X67 -> column 6
Calc:w68 -> column 7

Thanks,

Ron


Sub AddSheet()

    Dim lngSheets As Long
    Dim intCount As Integer
   
    'copy worksheet
    ActiveSheet.Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Unprotect Password:="1111"
    'remove "clear" and "create worksheet" buttons
    ActiveSheet.Shapes.Range(Array("Button 1", "Button 2")).Select
    Selection.Delete
    ActiveSheet.Range("O1:O3").Value = ""
        'remove formulas from worksheet
    With ActiveSheet.UsedRange
        .Value = .Value
    End With
   
    ' check for multiple tab names, ie BillSmith1, BillSmith2, etc
    For lngSheets = 1 To Sheets.Count
        If Left$(Sheets(lngSheets).Name, Len(Range("P1"))) = Range("P1") Then
            intCount = intCount + 1
        End If
    Next
 '   If intCount > 0 Then
        ActiveSheet.Name = Range("P1") & intCount + 1 & "A"
 '   Else
 '       ActiveSheet.Name = Range("P1") & intCount
 '   End If
    'reset password protection
    ActiveSheet.EnableSelection = xlNoSelection
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="1111"
   
    'Copy over Answer Sheet
    Sheets("Answer Sheet").Select
    ActiveSheet.Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Unprotect Password:="1111"
    ' remove formulas
    With ActiveSheet.UsedRange
        .Value = .Value
    End With
    ' clear secondary DISC if not shown
    If ActiveSheet.Range("A17").Value = "" Then
       Range("A17:E21").Select
       Selection.ClearContents
    End If
    ' rename answer sheet
    ActiveSheet.Name = Range("A1") & intCount + 1 & "B"
    ActiveSheet.EnableSelection = xlNoSelection
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="1111"
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
2 Comments
 
LVL 18

Accepted Solution

by:
krishnakrkc earned 500 total points
ID: 40596564
Hi

Sub CalcToSummary()
    
    Dim wksCalc         As Worksheet
    Dim wksSummary      As Worksheet
    Dim v
    
    
    Set wksCalc = Worksheets("Calc")
    Set wksSummary = Worksheets("Summary")
    
    With wksCalc
        v = Array(.Range("p1").Value, .Range("p3").Value, .Range("x71").Value, .Range("x73").Value, _
                .Range("w67").Value, .Range("x67").Value, .Range("w68").Value)
    End With
    
    wksSummary.Range("a" & wksSummary.Rows.Count).End(3)(2).Resize(, 7).Value = v
    
End Sub

Open in new window


Kris
0
 

Author Closing Comment

by:bikeski
ID: 40599496
Thanks Kris, worked like a charm. I just added a call to the original VBA code:

Call CalcToSummary()
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

733 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