+ Reply to Thread
Results 1 to 3 of 3

VBA code for cutting and pasting a table of varying rows from one worksheet to another

  1. #1
    Registered User
    Join Date
    08-20-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    1

    VBA code for cutting and pasting a table of varying rows from one worksheet to another

    I'm trying to put together VBA code to copy and paste a table from one worksheet to another worksheet in the same spreadsheet.

    The difficulty is that my code (when it works) is copying just the first row of data and duplicating it many times over.

    The Macro code that I've put together so far is as follows:

    ' Macro16 Macro
    '
    'Selection.AutoFill Destination:=Range("AR2:AU" & Range("A" & Rows.Count).End(xlUp).Row)
    'Range(Selection, Selection.End(xlDown)).Select
    '
    Sheets("All Other Hearings").Select
    Range("C2:R1000").Select
    Selection.AutoFill Destination:=Range("C2:R" & Range("C" & Rows.Count).End(xlUp).Row)
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("Payment Report").Select
    Range("A2").Select
    ActiveSheet.Paste
    Range("A2").Select
    Sheets("Dashboard").Select
    End Sub

    Is there anything obviously wrong with this code which is leading to the duplicated first row in all rows in the pasted to worksheet?

    Thanks in advance?

  2. #2
    Forum Contributor
    Join Date
    03-28-2018
    Location
    Houston, TX
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    127

    Re: VBA code for cutting and pasting a table of varying rows from one worksheet to another

    Please post an example workbook. This looks like a recorded macro. It would give me a better idea what exactly needs to happen if I can look at a sample workbook... preferably a ".xlsx"

    Thanks!

  3. #3
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA code for cutting and pasting a table of varying rows from one worksheet to another

    The way the code is written, it will fill the selected range C2:R1000 with whatever is on row 2 when the Autofill executes. Maybe if you uploaded a copy of your file or a mock up and explained what you are trying to do, we could get a better idea of what you need to do with the code. To upload a file, click 'Go Advanced' at the bottom of the reply box, then click 'Manage Attachments' and follow the menu.

    BTW, when posting code, use the code tags so the code will retain its formatting and be easier for responders to work with. To use the code tags, select the code with the mouse pointer, then click the pound symbol (#) in the reply tool box and it will put the code tags on for you. You can edit your original post to fix it before the moderator chides you for not using the tags.
    Last edited by JLGWhiz; 08-20-2019 at 10:33 AM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

+ 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. Cutting and pasting Filtered Rows
    By exnyorker55 in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 02-14-2018, 10:37 PM
  2. Trouble cutting and pasting rows
    By BrianSells in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-06-2015, 02:53 PM
  3. Cutting and Pasting rows loopwise as per the same value in Proposal(Column E)
    By mvneema in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2014, 04:40 PM
  4. VBA Cutting and Pasting from one worksheet to another based on value
    By aeewing in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-20-2013, 10:27 AM
  5. Cutting/Pasting data from one pivot table to another
    By Lord451 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-12-2012, 05:40 PM
  6. Cutting/Pasting Rows based on content PT 2
    By Lmsloman in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-21-2006, 06:36 AM
  7. [SOLVED] cutting and pasting rows from one sheet to another generates error
    By JT Spitz in forum Excel General
    Replies: 7
    Last Post: 02-14-2006, 03:10 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