Results 1 to 7 of 7

Setting range to last row in a table

Threaded View

  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:

    Sub PickingTotals()
        Dim myCell      As Range
        Dim currentSum  As Double
        For Each myCell In Worksheets("ALL DATA").Range("a2:a287,b2:b287")
            If myCell = vbNullString Then
                myCell = currentSum
                myCell.Interior.Color = 16777215
                currentSum = 0
            Else
                currentSum = currentSum + myCell
            End If
        Next myCell
    End Sub
    Attached Files Attached Files

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