+ Reply to Thread
Results 1 to 3 of 3

Copy data between two tables

  1. #1
    Registered User
    Join Date
    11-07-2019
    Location
    Rio de Janeiro, Brasil
    MS-Off Ver
    2016
    Posts
    1

    Copy data between two tables

    Hi

    I am quite new in VBA.

    I have two Excel Tables and I need to copy rows in table1 that meets a criteria on Table1 and paste them to the bottom of table2.

    I've tried many ways to do that without succes.

    The code I'm trying to run:

    Dim tabela As ListObject
    Dim newrow As ListRow

    ActiveWorkbook.Sheets("Compra").ListObjects("Compra").Range.AutoFilter Field:=7, Criteria1:=">0"
    ActiveSheet.ListObjects("Compra").DataBodyRange.SpecialCells(xlCellTypeVisible).Copy
    Set tabela = Worksheets("Histórico").ListObjects("BaseHst")
    Set newrow = tabela.ListRows.Add
    newrow.Range(1).PasteSpecial xlPasteValues
    If ActiveWorkbook.Sheets("Compra").FilterMode = True Then
    ActiveWorkbook.Sheets("Compra").ListObjects("Compra").Range.AutoFilter
    End If
    End Sub

    A new line is inserted at the bottom os the secon table and I get a meeesge about the failure of the Paste in Range method.

    Any comment will be welcome.

    Thank in advance
    Last edited by francorp; 11-08-2019 at 08:05 AM. Reason: Add sample code

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Copy data between two tables

    Read the banner at the top of this page. It is yellow. Then follow through.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Hi,

    an Excel basics EZ way thus without any code (but can be applied by code) is a filter and a copy …

+ 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. Copy out data from multiple tables
    By kay007 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-23-2019, 05:16 AM
  2. [SOLVED] Copy data from tables into other tables, using criteria and VBA (with example)?
    By LIL2606 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-20-2019, 04:12 AM
  3. [SOLVED] Trying to match data from two different tables and copy and paste data to one table
    By chelsea7A in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-12-2018, 10:35 PM
  4. Sort/copy Data into separate categorized tables
    By cgm990 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-29-2015, 10:36 AM
  5. Copy and paste data between tables in separate workbooks.
    By catigo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-17-2013, 04:41 PM
  6. Copy data from tables
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-15-2012, 11:00 AM
  7. Help with Excel tables to copy dynamic data update
    By gigiw1986 in forum Excel General
    Replies: 1
    Last Post: 04-24-2010, 06:54 AM

Tags for this Thread

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