We will first attempt to do this without using Offset. If the number of days in increased then we do not need to add any more code. Below are some more examples of using Offset Current Region returns a range of all the adjacent cells to the given range.
For Offset to be useful there needs to be some kind of relationship between the positions of the cells. In the screenshot below you can see the two current regions.
This follows the same hierarchy as in Excel so should be easy to understand.
To do something with Range you must first specify the workbook and worksheet it belongs to.
The Range property takes the same argument that most Excel Worksheet functions take e.g. The following example shows you how to place a value in a cell using the Range property.
As you can see Range is a member of the worksheet which in turn is a member of the Workbook.
This can come in very handy when you are debugging or writing code for the first time.
If we take any range of cells within the border and apply Current Region, we will get back the range of cells in the entire area. The code below will set the second column of the range to bold.
These can cause confusion as they do similar things and can lead to confusion In this post I will tackle each one, explain why you need it and when you should use it.
Let’s start with the simplest method of accessing cells – using the Range property of the worksheet.
This post covers everything you need to know about using Cells and Ranges in VBA.
You can read it from start to finish as it is laid out in a logical order.