Updating active cells into vba
To do something with Range you must first specify the workbook and worksheet it belongs to.For the rest of this post I will use the code name to reference the worksheet.(Note: Website members have access to the full webinar archive.) This is the third post dealing with the three main elements of VBA.These three elements are the Workbooks, Worksheets and Ranges/Cells. Almost everything you do in Excel starts and ends with Cells.You may be wondering what is the difference between Value, Value2 and the default: as it will always return the actual cell value(see this Stack Overflow answer.) The worksheet has a Range property which you can use to access cells in VBA.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 follows the same hierarchy as in Excel so should be easy to understand.
You can manually check the Current Region in Excel by selecting a range and pressing Ctrl Shift *.
If you want to return a range of cells then you can use Cells with Ranges as follows As you can see, you provide the start and end cell of the Range.
Sometimes it can be tricky to see which range you are dealing with when the value are all numbers.
Range has a property called Address which displays the letter/ number cell reference of any range.
This can come in very handy when you are debugging or writing code for the first time.