**Get the Excel file here
chrisjterrell....
**Grab the Free VBA Quick Reference Guide
www.chrisjterr...
Excel VBA Graspoing Row(s)/Column(s) might be easier than you think once you grasp each one's purpose.
In this video, we compare the difference between rows/columns (with an "s") and row/column (without and "s"). When I first started using VBA, this was super confusing. As I grew in my mastery of VBA, the difference became more apparent. Row/column returns the index or number of the associated row or column on the Sheet. For example, row two is the first row on the Sheet, and Column two is equal to column "B" on the worksheet. Rows/columns are a reference to the parent object. Said another way, rows/columns are a subset of the existing Sheet or Range. You can do a lot with the referenced row(s)/column(s). In this video, we focus on selecting rows/columns and counting row/column
The code below is returning the count into a cell using the range.
'===================== CODE========================
Sub RowsColumns()
'Column is the property, Select is a methodSheet1.Rows(1).Select 'Rows is the property, Select is a method
Sheet1.Columns(1).Select 'reference the index one row at a time
Sheet1.Columns("A:J").Select 'reference multiple columns
Sheet1.Rows(1).Select 'reference the index one row at a time
Sheet1.Rows("1:10").Select 'reference multiple columns
Range("B20").Select
Range("B19") = ActiveCell.Address & " Active Cell"
Range("B20") = ActiveCell.Row
Range("B20") = ActiveCell.Column
Range("B19").CurrentRegion.ClearContents
Range("B20:G30").Select
Range("B19") = Selection.Address & " Selected Range"
Range("B20") = Range("B20:G30").Row & " Row in Range"
Range("B20") = Range("B20:G30").Column & " Column In Range"
Range("B19").CurrentRegion.ClearContents
Range("B20") = Range("B20:G30").Rows.Count & " Rows"
Range("B20") = Range("B20:G30").Columns.Count & " Columns"
Range("B20:G30").Rows(2).Select
Range("B20:G30").Columns(2).Select
End Sub
23 сен 2024