In Excel we deal with cells, rows, columns, worksheet, ranges, etc. Today, let us find how to identify these elements using vba.
To use cells in vba we have to define as cell(1,1), which means the cell where the first row and first column is intersected. The same we can define in vba in a different way as Range(“A1”), which is more simpler than cell, as there is no hardship in remembering column number, we can identify easily with alphabetical declaration of the column in excel.
To select A5, we can use:
Cells(5,1).select in which the starting 5 refers to the row and the latter refers to column.
or simpler way is:
VBA Beginners mostly use cells to identify the ranges. Better use Range command to refer the range element rather than defining cells. It will be easy to identify and remember as well.
Cells reference is used only when you want to select all the cells in a sheet.
or to clear all the contents of the sheet
Range(“G5”).Select Selects Cell G5 Range(“D5, M10, Z16, ZZ202”).select Selects noncontiguos cells, A1, B2. Range(“A1:E200”).select Selects ranges A1:E200 Range(“A1:B10,D6:Z20”).select Select noncontiguos ranges A1:B10 and D6:Z20 Range(“January”).select Select range named “January” Range(“Order”,”Sales”,”Purchase”).select Selects named ranges Order, Sales, Purchase Range(“Order”,”January”,”Sales”,”A6″).select Selects named ranges as well as cells A6
These are the different ways in VBA to select cells and ranges and named ranges.