Create a Range

Tags
Summary

Set rSomething = Range(top left cell, bottom right cell)

Situation

You have a set of records in a worksheet that you want to process.

Needs

A worksheet with records in it.

Provides

An object that you can loop across.

Action

Example:

  • Dim rGoatDataTable As Range
  •  
  • 'Set up the Range object.
  • Set rGoatDataTable = Range(Cells(3, 1), Cells(3, 1).End(xlToRight).End(xlDown))

This creates a Range object. The upper left cell is C1. The lower right cell is however far you get until you run out of data (find an empty cell) to the right and below.

Where referenced