15 YouTube views, likes subscribers in 10 minutes. Free!
Get Free YouTube Subscribers, Views and Likes

Selecting Cells in VBA - Sheets Ranges ActiveCell SpecialCells End and Offset - Code Included

Follow
EverydayVBA

Grab the Free VBA Quick Reference Guide
https://chrisjterrell.com/p/gettings...
When you start coding you will want to know how to Select Cells. In many ways, this is one of the first steps in your journey.

In this video, we review selecting Sheets (or worksheets), Ranges which are a child of sheets and cells which are a child of both ranges and sheets.

Things to keep in mind before you select a cell if the sheet is referenced (like Sheets("Sheet1").cells(1,1).select) you will need to select that sheet or make it the active sheet.

Select activates the Worksheet, Range, or Cell. You can also use the Selection property object that represents the currently active selection.

One last thing, while recording a macro selection is one of the most commonly returned item even though it may not be essential to what you are trying to accomplish.

Code:
Sub SelectCell()

Sheets("Sheet1").Select

Range("A1").Select
Range("A1:B10").Select

Cells(1, 1).Select


Range("C1:D10").Select
Range("C1:D10").Cells(2, 1).Select

Debug.Print ActiveCell.Row
Debug.Print ActiveCell.Column

Debug.Print Cells.SpecialCells(xlCellTypeLastCell).Row
Debug.Print Cells.SpecialCells(xlCellTypeLastCell).Column

ActiveCell.Cells.End(xlUp).Select

Range("D9").Select
Range("D9").Offset(1, 1).Select
Range("D9").Offset(1, 1).Select

Sheets("Sheet1").Select
Sheets("Sheet1").Cells(1, 1).Select

Debug.Print Selection.Row

Selection.Font.Bold = True
Range("B8").Font.Bold = True

End Sub

posted by axigantartz