+ Reply to Thread
Results 1 to 4 of 4

Adding rows of content below a table with VBA code

  1. #1
    Registered User
    Join Date
    12-22-2022
    Location
    Madrid, Spain
    MS-Off Ver
    2021
    Posts
    1

    Question Adding rows of content below a table with VBA code

    Hello everybody,

    This is my first post, so I want to greet you all and introduce myself. I'm new to this VBA stuff. I had recorded macros before, but the first time I opened the VBE window was actually 3 days ago, and I've been learning the basics ever since. The problem I encountered is:

    I have a first worksheet called "Database" where several tables (same columns, but different number of rows and content) are stored. ('Table1', 'Table2', 'Table3'...):
    Captura.PNG
    Then, a second worksheet "WorkTable" where only a global table is stored, 'GlobalTable'. That 'GlobalTable' is set to store combined data from the tables from the database:
    Captura4.PNG

    The basic operation I want to do is adding, for instance, 'Table1' below 'GlobalTable'.This is the code I used:

    Please Login or Register  to view this content.
    First I store how many rows my 'GlobalTable' has. Then I store how many rows the table I want to add has, in this case 'Table1'. Then I add this number of empty rows below 'GlobalTable'. Then I copy and paste the 'Table1', and when pasting the following error pops up: error 1004 pastespecial method of range class failed

    This is the desired result:
    Captura3.PNG

    I would appreciate any help on how to solve this, tips of other ways of coding this, and some explanation on why my code doesn't work!

    Thank you all for your time.

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Adding rows of content below a table with VBA code

    Probably not the help you were looking for but if you are learning VBA and interested in tables and VBA this is one of the best articles I have read.
    https://www.thespreadsheetguru.com/b...t-excel-tables
    Last edited by skywriter; 12-22-2022 at 07:56 PM. Reason: Issue with link.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  3. #3
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Adding rows of content below a table with VBA code

    Hi jorgeranio20,

    I'm not an expert and I'm still learning too...
    I think MAYBE it's because the copy cliboard is gone at the time the code execute the "add table row" in the loop.

    So maybe try the loop code first, then the copy code, then the paste code.
    Please Login or Register  to view this content.
    Also, I think you can just directly do it without the loop to add a row for the table :

    Please Login or Register  to view this content.
    And if you like to have a shorter code :
    Please Login or Register  to view this content.
    Last edited by karmapala; 12-23-2022 at 03:44 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Adding rows of content below a table with VBA code

    Greetings to all. It will suffice to do like this:

    Please Login or Register  to view this content.
    Or:

    Please Login or Register  to view this content.
    Last edited by beyond Excel; 12-23-2022 at 09:27 AM.
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

+ 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. Replies: 2
    Last Post: 12-24-2018, 11:27 AM
  2. VBA code to extract rows based on content
    By chrisellis250 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-07-2018, 10:10 AM
  3. Replies: 13
    Last Post: 07-16-2016, 10:53 PM
  4. Adding Multiple Rows Depending on Column Content
    By ryanb4614 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2014, 09:58 AM
  5. Adding rows based on content, organizing data
    By Mark.Small in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-20-2012, 12:16 AM
  6. Adding rows based on content, organizing data.
    By Mark.Small in forum Excel General
    Replies: 0
    Last Post: 01-17-2012, 09:31 PM
  7. adding content to a table by filling a sheet
    By Borgas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-18-2006, 07:50 PM

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