Selecting Cells in VBA - Sheets, Ranges, ActiveCell, SpecialCells, End, and Offset - Code Included
Grab the Free VBA Quick Reference Guide
https://chrisjterrell.com/p/getting-started
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
Видео Selecting Cells in VBA - Sheets, Ranges, ActiveCell, SpecialCells, End, and Offset - Code Included канала EverydayVBA
https://chrisjterrell.com/p/getting-started
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
Видео Selecting Cells in VBA - Sheets, Ranges, ActiveCell, SpecialCells, End, and Offset - Code Included канала EverydayVBA
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
Excel VBA: Referring to Ranges & Writing to Cells (Range, Cells, Offset, Names)Excel VBA Introduction Part 5 - Selecting Cells (Range, Cells, Activecell, End, Offset)Excel VBA - Selection, Active Cell, Range - Part 7Automate Copying of Column Data from Sheet to Sheet Using Excel VBAExcel VBA - Cell ReferencingExcel OFFSET Function for Dynamic Calculations - Explained in Simple Steps5 Things I wish I knew When I started using Excel VBASelect Multiple Cells that Match Criteria ExcelVbaIsFunFinding the Last Row or Column three different ways in Excel VBA - Code IncludedMaster Excel MACROS & VBA in ONLY 1 HOUR!Excel VBA Basics #8 - Find the LAST ROW or COLUMN dynamically and clearing out your last reportVBA to Copy and Paste Rows if Condition is Met - Excel VBA Example by ExcelDestinationMoving or Copying Data from one Worksheet to another Worksheet using VBA in Excel - Code IncludedExcel VBA Activate vs Select vs Selection vs ActiveCellExcel VBA basics: Data types, DIM & SET (Learn to use them correctly)Run a Macro when a User Changes a Specific Cell, Range, or Any Cell in ExcelAutofill using VBA Code - Autofill Formula downHow to Use Arrays Instead of Ranges in Excel VBAFind Next Empty Row for Data Entry using Excel VBAExcel Visual Basic (VBA) for Beginners - Part 1 of 4: Buttons and Macros