![excel vba examples of choosing cells excel vba examples of choosing cells](https://images.squarespace-cdn.com/content/v1/57cfc8a3d482e945c66724f7/1474032567594-NPMJFTR20X6KRV3LCNYA/image-asset.jpeg)
EXCEL VBA EXAMPLES OF CHOOSING CELLS CODE
Sample code # 7: Selecting non-contiguous data using union You can also select non-contiguous data, though you may not find much practical use for it Sub nonContiguous() Sample code # 6: Selecting non-contiguous data For instance, Application.Union(Range("RangeA"), Range("RangeB")).Select You can also use named ranges, instead of specifying the actual range. Sample code # 5: Selection using named ranges Sub RangeSelect()ĪctiveSheet.Range("B2").End(xlDown).SelectĪnd if you want to select the entire range of data in a column: Sheet1.Range("C2", ActiveSheet.Range("C2").End(xlDown)).Select column “B”) that has data or is a non-blank cell. The following sample code is used to select the last row of the specified column (ex. for a offset of -1 rows on range C3:F8 will result in C2:F7 and an offset of -1 columns will eventually result in the range B2:E7 Sample code # 4: Selecting the last cell of a column of contiguous data Note that the offset works on the entire range, i.e. To include rows above or columns to the left of the specified range, use negative integers for offset Sub RangeSelect()ĪctiveSheet.Range("C3:F8").Offset(-1, -1).Select Sub RangeSelect()ĪctiveSheet.Range("B1:E5").Offset(2, 0).Select This is commonly used when selecting a range of data, skipping the header row. Sub RangeSelect()Īpplication.Goto ActiveWorkbook.Sheets("AnotherWorksheet").Range("B2:F9")ĪctiveSheet.Range(Cells(2, 2), Cells(9, 6)).Select However, you can still use the “select” method by activating the target worksheet before selecting the specified range. This is another way of selecting a range of cells by using “Application.Goto” which basically has the same result as “lect” method. Notice that the sample code below doesn’t require us to have “select” text.
![excel vba examples of choosing cells excel vba examples of choosing cells](https://www.al-mscoastallaw.com/wp-content/uploads/2021/12/excel-vba-worksheet-protect-example.jpg)
Sample code # 2: Selecting a range of cells on another worksheet in the same workbook Sample code # 1: Selecting a range of cells on the active worksheet Sub RangeSelect() Sample code # 12: Selecting a range and then resize the selection.Sample code # 11: Selecting a range in a sheet from another workbook.Sample code # 10: Selecting an entire row.Sample code # 9: Selecting a rectangular range around specified cell including blanks.Sample code # 8: Selecting a rectangular range around specified cell.Sample code # 7: Selecting intersection of two ranges.Sample code # 7: Selecting non-contiguous data using union.Sample code # 6: Selecting non-contiguous data.Sample code # 5: Selection using named ranges.Sample code # 4: Selecting the last cell of a column of contiguous data.Sample code # 3: Selecting a range of cells offset from a specified range Sample code # 2: Selecting a range of cells on another worksheet in the same workbook.Sample code # 1: Selecting a range of cells on the active worksheet.