This code was posted by Leith Ross from another thread (http://www.excelforum.com/excel-prog...le-sheets.html). It creates a summary sheet from specific cells of the other worksheets in a given workbook (this example grabs the values from cells G5, G6, and G18 from all of the worksheets and creates a summary table of these values).
I'm not that familiar with programming in excel, and I only have a basic working knowledge of VB. When I add code to create a new workbook, that new workbook becomes the "dominant" workbook.
My question is: How can I get this code to create the summary table in a new workbook instead of a new worksheet? (I'm summarizing from a government form that doesn't allow for creating a new worksheet).
I've commented out the code I entered to create the new workbook
'Thread: http://www.excelforum.com/excel-programming/783136-macro-to-copy-specific-cells-from-multiple-sheets.html
'Poster: Costasg
'Written: July 06, 2011
'Author: Leith Ross
Sub Summarize()
Dim Cell As Range
Dim Data(2) As Variant
Dim R As Long
Dim Rng As Range
Dim RngEnd As Range
Dim SumWks As Worksheet
Dim Wks As Worksheet
'Look for the Summary worksheet
On Error Resume Next
' create new workbook
'Set NewBook = Workbooks.Add.Worksheets(1)
'With NewBook
' .Title = "Fish Summary"
' .Subject = "Permit"
' .SaveAs Filename:="SummaryTable.xls"
'End With
Set SumWks = Worksheets("Summary")
If SumWks Is Nothing Then
'Create the worksheet if it does not exist
Set SumWks = Worksheets.Add(After:=Worksheets(Worksheets.Count))
SumWks.Name = "Summary"
End If
On Error GoTo 0
'Row 1 has column headers
Set Rng = SumWks.Range("A2")
Set RngEnd = SumWks.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Rng = SumWks.Range(Rng, RngEnd).Offset(1, 0)
Application.ScreenUpdating = False
For Each Wks In Worksheets
Select Case LCase(Wks.Name)
Case Is <> "main", "summary"
Data(0) = Wks.Range("G5").Value
Data(1) = Wks.Range("G6").Value
Data(2) = Wks.Range("G18").Value
Rng.Resize(1, 3).Offset(R, 0).Value = Data
R = R + 1
Case Else
'Do nothing
End Select
Next Wks
Application.ScreenUpdating = True
End Sub
Bookmarks