+ Reply to Thread
Results 1 to 4 of 4

Copy Paste Print Between two worksheets

Hybrid View

  1. #1
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Exclamation Copy Paste Print Between two worksheets

    Hello Forum,
    There are two workbooks "white" & "Black".
    The Problem has three parts :
    step 1:
    Copy date From "Black" Sheet1 Column D and paste in this format .Copy Paste this till the end of data string.
    step 2:
    Now if
    old>0,and Bold> 0 and Cold>0,then copy to new Work Book " white" Placed on Desktop ,sheet A
    step 3:
    Print the Details from work Book "white",sheetA.
    Any inputs are welcome.
    Happy Holiday !
    Attached Files Attached Files
    N

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy Paste Print Between two worksheets

    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
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Copy Paste Print Between two worksheets

    Thanks for the response I will revert with the outcome ..
    Thanks Once again Leith,Happy Holidays

  4. #4
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Copy Paste Print Between two worksheets

    Hello Leith,
    I notice that the date is not getting picked up the way it should be in WB Black from Sheet1 to Sheet2 in cell D2.
    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1