+ Reply to Thread
Results 1 to 7 of 7

Setting range to last row in a table

  1. #1
    Registered User
    Join Date
    09-06-2018
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    24

    Setting range to last row in a table

    Hi everyone,

    I'm a complete novice at excel and vba. If you see the attached worksheet, my goal was to have a code that would fill each blank cell in columns A and B with the sum of the cells before it, until it reached another blank cell. I searched online and have found a code that works, see below, however it is a defined range. I will be inputting new data daily and therefore need it to automatically adjust the range to the last row in the table. I've searched the internet for a couple of weeks now trying to find a solution that works to no avail. My current code is:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Setting range to last row in a table

    Hi,

    Try this code which I've commented to help you understand what's happening:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Registered User
    Join Date
    09-06-2018
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    24

    Re: Setting range to last row in a table

    Thank you for your quick reply.

    I've copied it over into my spreadsheet, and changed this line
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    as that is where the columns are on my full sheet. When I run the code, it says error "9", Subscript out of range and highlights this column
    Please Login or Register  to view this content.
    .

    Is there anything else I should change?

    Thank you!

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Setting range to last row in a table

    Hehe. Change all "thisCol - 1" to be "thisCol - 25" then

    WBD

  5. #5
    Registered User
    Join Date
    09-06-2018
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    24

    Re: Setting range to last row in a table

    Worked an absolute treat!!! Thank you so much, the amount of time I've spent trying to work it out myself is unbelievable haha.

    Thanks again!

  6. #6
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Setting range to last row in a table

    No problem. Remember to mark the thread as solved and, if you're so inclined, help me build my reputation :D

    WBD

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Setting range to last row in a table

    Please Login or Register  to view this content.

+ 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. [SOLVED] Setting range located directly beneath a table
    By ddoctor in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-20-2017, 05:56 PM
  2. Replies: 2
    Last Post: 09-01-2017, 05:43 PM
  3. How to stop a table from being deleted when setting a range?
    By Mutak in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-12-2016, 09:17 AM
  4. Setting a range of cells, within a table, from text cells
    By sligh in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-14-2015, 04:40 PM
  5. Replies: 15
    Last Post: 09-10-2013, 05:31 AM
  6. Replies: 11
    Last Post: 07-15-2012, 04:08 PM
  7. [SOLVED] Setting Range in Pivot Table
    By Dhiraj in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-14-2005, 09:05 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