VBA MOD01 Referencing Ranges
Different Ways of Referencing Ranges
▪ Range ()
▪ Cells property of the range object
▪ Offset
▪ Defined Names
▪ Reference entire rows
▪ Reference entire columns
▪ Autofit all columns
Sub ReferToCell()
ActiveSheet.Cells.Clear
Range("A1").Value = "1st" 'Cells(1,1)= "1st"
Range("A2:C2").Value = "2nd"
Range("A3,C3").Value = "3rd"
Range("A" & 4, "C" & 4).Value = "4rth"
Range("A5", "C5").Value = "5th"
Range("A6:C8").Cells(1, 2).Value = "6th"
Range("A1").Offset(7, 2).Value = "7th"
Range("A1:B1").Offset(8, 1).Value = "8th"
Range("LastOne").Value = "10th"
End Sub
Referencing Entire Rows/Columns
Public Sub ReferencingEntireRowsColumns()
Range("2:5").RowHeight = 30 'ROW 2,3,4&5 HAVE HEIGHT OF 30
Range("7:7,9:9,11:11").RowHeight = 30 'ROW 7,9 &11 HEIGHT CHANGES
' TO 30 ROWS 8, 10 HEIGHT
' DOES NOT CHANGE
Range("A:A , C:C").ColumnWidth = 20 'ONLY COLUMN A AND C WIDTH IS
'CHANGE WHILE COLUMN B IS UNTOUCHED
End Sub
Comments
Post a Comment