Excel VBA Get Range Reference To Last Row With Data

Опубликовано: 09 Ноябрь 2024
на канале: Sean Johnson
7,181
64

How To Select The Last Row With Data
Excel VBA book (affiliate) with reviews https://amzn.to/3axlqih

This tutorial shows you how to use vba to get a reference to an Excel Data Range and then iterate over each cell in that last row and apply custom formatting to it.

Associated blog post with download link for this tutorial can be found at https://www.businessprogrammer.com/ex...


If you found this tutorial helpful consider supporting this channel with a steaming hot cup of coffee... https://buymeacoffee.com/seanjohnson


I use the following methods of the excel range object namely offset and resize to create multiple vba range objects.

Firstly I create an excel subroutine within that subroutine, three excel vba range objects are created, the first uses the currentregion method of the range object to referer to the excel data range, then I create a new range object by resizing that range to one row and refering to the top row of that spreadsheet range.

Finally a range reference is created to offset the first range reference by the number of rows in the data range less one in order to find the last row in the data table range.

I then use a for each next routine to iterate over the last row of the data range and use range.intersect in order to know what cell the range is currently referring to in order to apply custom formatting to this cell.

Video Production
===============
Sony Camera: https://amzn.to/3mqyqfu
Elgato HDMI Stream Capture: https://amzn.to/2Yfyrum

Microphones
---------------
Screen Casting: https://amzn.to/3a2TnHN
Microphone and Arm : https://amzn.to/3iwvL2S
Talking To Camera: https://amzn.to/3FqXI6b

Video Kit
-------------
Lights
Elgato video Lights: https://amzn.to/3sSK3xg
Background Light: https://amzn.to/3uTXyPh

Note Taking
--------------
Rocketbook reusable notebook https://amzn.to/3sSK3xg

DISCLAIMER: This video and description contains affiliate links, this means if you click on one of the product links, I’ll receive a small commission.