Hello nuttycongo123,
The macro below has been added to the attached workbook. A button on "Sheet2" will run the macro. The macro checks to see if the workbook "White.xls" or the name you decide to use exists. If it does then you are asked if you want to overwrite the existing data. If you answer yes then the old data is overwritten with the current data in "Black.xls", otherwise the data from "Black.xls" will be appended to "White.xls". You also have the option of canceling the macro.
' Thread: http://www.excelforum.com/excel-programming/806814-copy-paste-print-between-two-worksheets.html
' Poster: nuttycongo123
' Written: December 22, 2011
' Author: Leith Ross
Sub CopyAndPrint()
Dim Exists As Boolean
Dim FilePath As String
Dim Headers As Range
Dim NewWkb As Workbook
Dim NewWkbName As String
Dim R As Long
Dim Rng As Range
Dim RngEnd As Range
Dim Wks As Worksheet
Dim Wkb As Workbook
Dim WSH As Object
NewWkbName = "White.xls"
Set Wks = Worksheets("Sheet2")
Set Rng = Wks.Range("A3:D3")
Set Headers = Rng.Offset(-1, 0)
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Wks.Range(Rng, RngEnd)
Set WSH = CreateObject("WScript.Shell")
FilePath = WSH.SpecialFolders("Desktop") & "\"
On Error Resume Next
Set NewWkb = Workbooks.Open(FilePath & NewWkbName)
If Err <> 0 Then
Set NewWkb = Workbooks.Add(xlWBATWorksheet)
Else
Exists = True
Answer = MsgBox("The workbook " & "'" & FilePath & NewWkbName & "' already exists." & vbCrLf _
& "Do you want to overwrite the data?", vbYesNoCancel)
Select Case Answer
Case vbYes
NewWkb.Sheets(1).UsedRange.Clear
Case vbNo
R = NewWkb.Sheets(1).UsedRange.Rows.Count - 1
Case vbCancel
Exit Sub
End Select
End If
On Error GoTo 0
Headers.Copy
NewWkb.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteColumnWidths
NewWkb.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteAll
NewWkb.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteValues
For Each Row In Rng.Rows
If WorksheetFunction.Sum(Row.Resize(1, 3)) > 2 Then
Row.EntireRow.Copy
NewWkb.Sheets(1).Range("A2").Offset(R, 0).PasteSpecial Paste:=xlPasteAll
R = R + 1
End If
Next Row
If Not Exists Then
NewWkb.SaveAs FileName:=FilePath & NewWkbName
Else
NewWkb.Save
End If
Workbooks(NewWkbName).PrintOut
NewWkb.Close
End Sub
Bookmarks