+ Reply to Thread
Results 1 to 5 of 5

Sub for adding to a table

  1. #1
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    583

    Sub for adding to a table

    I found the following sub for adding a new record with multiple fields to a table, but it keeps bombing out at the row that reads:

    Set lastRow = table.ListRows(table.ListRows.Count).Range

    With an error:
    Run-time error '9':
    Subscript out of range

    The only modifications I made to it were:
    I selected the sheet that has the table on it just after the Dim statements
    In the next two lines I entered the name of the worksheet, then the name of the table.

    I am passing to it a table name that is a string tblRecordLog, and a 5 item array called Values(), as in:
    Call AddDataRow("tblRecordLog", Values())

    Also I found if I didn't put the word "Call" in there it showed that line as an error (Which I don't understand either as I am used to not having to first type "Call"!).

    Can anyone spot what is going wrong, let my know why, and how to fix?

    Please Login or Register  to view this content.
    Still learning much by fire, appreciate the help immensely.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Sub for adding to a table

    you code works well on my test sheet, attach please a sample file
    If solved remember to mark Thread as solved

  3. #3
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Sub for adding to a table

    If there is no data in the table, that error will occur.

    Please Login or Register  to view this content.
    When you call the routine, you must either use Call and enclose the parameters in parentheses, or do not use call and do not use parentheses. Parentheses may only be used if you use Call or you are returning a value from a function or you must dereference a parameter.
    Last edited by Izandol; 01-29-2014 at 04:28 AM.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  4. #4
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    583

    Re: Sub for adding to a table

    You hit it on the head; it is a "virgin" table!

    Thank-you for your response!

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Sub for adding to a table

    You are welcome.

+ 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. Expand a table by adding rows ( table feature 2007 and later)
    By Pepe Le Mokko in forum Excel General
    Replies: 3
    Last Post: 08-13-2013, 05:12 AM
  2. adding a row to a table?
    By oneblondebrow in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-23-2013, 11:01 PM
  3. Adding formula to active table and for pivot table in macro
    By Jerseynjphillypa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2012, 08:12 AM
  4. Adding data to a table, from another table..reverse vlookup??
    By Speshul in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-24-2012, 04:06 AM
  5. Adding table captions before having the table?
    By dylanemcgregor in forum Word Formatting & General
    Replies: 0
    Last Post: 12-01-2009, 06:56 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