+ Reply to Thread
Results 1 to 14 of 14

Select ,copy paste and print sepratly.

Hybrid View

  1. #1
    Forum Contributor visha_1984's Avatar
    Join Date
    11-27-2012
    Location
    Pune,India
    MS-Off Ver
    Excel 2013
    Posts
    309

    Select ,copy paste and print sepratly.

    Hi ,Team

    I am trying to copy 1 cp name ,sr no 01 ,sr no 02 and qty in seprate sheet with header and print it with specific size.
    any help with vba code much appriciate .

    Thanks in advance i have attached excel sheet.

    Little Bump.
    Attached Files Attached Files
    Last edited by visha_1984; 04-07-2014 at 01:26 AM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Select ,copy paste and print sepratly.

    Hi visha

    Try this
    Option Explicit
    
    Sub Sep_Print()
      Dim ws As Worksheet, ws1 As Worksheet, ws2 As Worksheet
      Dim LR As Long, LC As Long
      Dim cel As Range
    
      Set ws = Sheets("Sheet1")
    
      Application.ScreenUpdating = False
      If Not Evaluate("ISREF(Lists!A1)") Then
        Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Lists"
      Else
        Sheets("Lists").Cells.ClearContents
      End If
    
      Set ws1 = Sheets("Lists")
    
      With ws
        LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                         SearchDirection:=xlPrevious).Row
        LC = .Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
                         SearchDirection:=xlPrevious).Column
        .Range("A1:A" & LR).AdvancedFilter Action:=xlFilterCopy, _
                                           CopyToRange:=ws1.Range("A1"), Unique:=True
    
        ActiveWorkbook.Names.Add Name:="CPName", RefersTo:= _
                                 "=OFFSET(Lists!$A$2,0,0,(COUNTA(Lists!$A:$A)-1),1)"
    
        If Not Evaluate("ISREF(Temp!A1)") Then
          Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Temp"
        Else
          Sheets("Temp").Cells.ClearContents
        End If
        Set ws2 = Sheets("Temp")
        For Each cel In Range("CPName")
          .Range("A1:D" & LR).AutoFilter Field:=1, Criteria1:=cel.Value
          With .Range(.Cells(1, 1), .Cells(LR, LC)).SpecialCells(xlCellTypeVisible).Copy
            With ws2
              .Range("A1").PasteSpecial (xlPasteColumnWidths)
              .Range("A1").PasteSpecial (xlPasteValues)
              .PrintPreview  '<---Change to .PrintOut to print Sheet
              .Cells.Clear
            End With
            ws.ShowAllData
          End With
        Next cel
    
      End With
      Application.DisplayAlerts = False
      ws2.Delete
      ws1.Delete
      Application.DisplayAlerts = True
      Application.ScreenUpdating = True
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Contributor visha_1984's Avatar
    Join Date
    11-27-2012
    Location
    Pune,India
    MS-Off Ver
    Excel 2013
    Posts
    309

    Re: Select ,copy paste and print sepratly.

    Thanks for reply

    showing error 400.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Select ,copy paste and print sepratly.

    Hi visha

    Click the Button in the attached...works for me...
    Attached Files Attached Files

  5. #5
    Forum Contributor visha_1984's Avatar
    Join Date
    11-27-2012
    Location
    Pune,India
    MS-Off Ver
    Excel 2013
    Posts
    309

    Re: Select ,copy paste and print sepratly.

    Quote Originally Posted by jaslake View Post
    Hi visha

    Click the Button in the attached...works for me...
    Thank u very much one little confusion i want to print whole page at one time, is it possible otherwise ok no problem.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Select ,copy paste and print sepratly.

    Hi visha

    Change the indicated Line of Code
    For Each cel In Range("CPName")
          .Range("A1:D" & LR).AutoFilter Field:=1, Criteria1:=cel.Value
          With .Range(.Cells(1, 1), .Cells(LR, LC)).SpecialCells(xlCellTypeVisible).Copy
            With ws2
              .Range("A1").PasteSpecial (xlPasteColumnWidths)
              .Range("A1").PasteSpecial (xlPasteValues)
              .PrintPreview  '<---Change to .PrintOut
              .Cells.Clear
            End With
            ws.ShowAllData
          End With
        Next cel

  7. #7
    Forum Contributor visha_1984's Avatar
    Join Date
    11-27-2012
    Location
    Pune,India
    MS-Off Ver
    Excel 2013
    Posts
    309

    Re: Select ,copy paste and print sepratly.

    Thanku very much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Select, copy and print data into separate columns
    By kelwood in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-08-2012, 03:46 PM
  2. How to select cell C1, copy paste then C2, copy paste then C3 etc
    By s45yth in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-07-2011, 07:15 AM
  3. Seach, Copy, select paste location, paste using macros
    By helpdave in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-16-2010, 11:36 PM
  4. macro to select data paste/print
    By Anthony in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-30-2005, 01:06 PM
  5. macro to select data/paste/print
    By Anthony in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-29-2005, 05:06 AM

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