+ Reply to Thread
Results 1 to 4 of 4

How to select certain rows then copy/paster to new wb

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    818

    How to select certain rows then copy/paster to new wb

    Hello All,
    How I can select a certain number of rows in same ws then copy/paste/save as new wb?

    Let says: row 1:1 is header
    data from A2:Z100
    I want to select "A1:Z10" then copy/paste ===> save as newFname1
    Then select "A11:Z20" then copy/paste ===> save as newFname2 (this should also select the header as well)
    do until to last row.

    Regards,
    tt3
    Last edited by tuongtu3; 10-20-2013 at 06:09 PM. Reason: Solved

  2. #2
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    818

    Re: How to select certain rows then copy/paster to new wb

    Hello All:
    I tried the below code but if there's any better code I would appreciate for your help:

    Sub SelectCertainRows_C/P()
    
    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Worksheets("Sheet1")
    Set ws2 = Worksheets("Sheet2")
    Dim Lr1 As Long, Lr2 As Long
    Lr1 = ws1.Range("A" & Range("A" & Rows.Count).End(xlUp).Row)
    Lr2 = ws2.Range("A" & Range("A" & Rows.Count).End(xlUp).Row)
    Do Until ws1.Range("A2").Value = ""
    ws1.Range("A1:P1").Copy Destination:=ws2.Range("A1")   'Header
    ws1.Range("A2:P3").Copy Destination:=ws2.Range("A2")
    ws1.Range("A2:P3").Delete Shift:=xlUp
    
    ws2.Activate
    
    Call Macro: SaveWSAsNewWB
    
    ws1.Activate
    Loop
        
    End Sub
    Regards,
    tt3

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: How to select certain rows then copy/paster to new wb

    Hi, tt3,

    based on your first post maybe
    Sub EF961744()
    Dim lngCounter As Long
    Dim lngLast As Long
    Dim lngNewNr As Long
    
    Const clngROW_NUMBER As Long = 10
    
    Do While Range("A2").Value <> ""
      lngNewNr = lngNewNr + 1
      Range("A1:Z" & clngROW_NUMBER).Copy
      Workbooks.Add
      ActiveSheet.Range("A1").PasteSpecial xlPasteValues
      ActiveWorkbook.SaveAs "C:\temp\FName " & lngNewNr & ".xlsx", FileFormat:=51
      ActiveWorkbook.Close False
      Range("A2:Z" & clngROW_NUMBER).Delete xlShiftUp
    Loop
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    818

    Re: How to select certain rows then copy/paster to new wb

    Hi HaHoBe,
    That's perfect. Thank you very much for your time and help.

    Regards,
    tt3

+ 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. Paster Special Picture in VBA
    By GaryMcV in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-08-2012, 08:44 AM
  2. Code that will select and copy only so many rows
    By Traymond in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-23-2009, 12:10 PM
  3. Copy and Paster an autosum to new workbook
    By pauldaddyadams in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-03-2008, 06:06 AM
  4. I've just lost my ability to copy and paster in Excel.
    By leprechaun in forum Excel General
    Replies: 0
    Last Post: 11-30-2005, 09:55 AM
  5. [SOLVED] Select rows and copy to another sheet.
    By Juan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-28-2005, 08:06 PM

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