Sub RangesTest() '' e25
Dim rng As Range
Dim value As Variant
Set rng = Range(Cells(1, 1), Cells(10, 4))
' Range Properties
Range("A12") = "Columns: " & rng.Columns.Count
Range("A13") = "Rows: " & rng.Rows.Count
Range("A14") = "Cells: " & rng.Cells.Count
' Offset from a cell
Range("A12").Offset(0, 3) = "Offset from ""A12"""
' Font
With rng.Font
.Bold = True
.Name = "Times New Roman"
.color = RGB(0, 0, 255)
.Size = 12
End With
' Copy and Paste
Range("A16") = "Copy and Paste:"
rng.Copy
ActiveSheet.Range("A17").PasteSpecial Paste:=xlPasteValues
' AutoFit Contents
Range("E28") = "AutoFit contents of this cell"
Columns("E").AutoFit
' Store the values in the range to the Array
Dim DirArray As Variant
DirArray = rng.value
Range("A28") = "Array size = " & UBound(DirArray) & " x " & UBound(DirArray, 2)
With ActiveSheet.UsedRange
' Address
Cells(.Rows.Count + 1, 1) = "Used Range: " & .Address
' Last cell in UsedRange
Cells(.Rows.Count + 1, .Columns.Count) = "Last Cell"
End With
End Sub
(function() {
var oSheet = Api.GetActiveSheet();
var oRange = oSheet.GetRange(oSheet.GetRangeByNumber(0,0), oSheet.GetRangeByNumber(9,3));
console.log(oRange.Address);
// Range Properties
oSheet.GetRange("A12").SetValue("Columns: " + oRange.GetCols().Count);
oSheet.GetRange("A13").SetValue("Rows: " + oRange.GetRows().Count);
oSheet.GetRange("A14").SetValue("Cells: " + oRange.GetCells().Count);
// Offset from a cell
var oCell_offset = oSheet.GetRange("A12");
oCell_offset.SetOffset(0, 3);
oCell_offset.SetValue('Offset from "A12"');
// Copy and Paste
oSheet.GetRange("A16").SetValue("Copy and Paste:");
oRange.Copy(oSheet.GetRange("A17"));
// Font
oRange.SetFontName("Arial");
oRange.SetFontColor(Api.CreateColorFromRGB(0, 0, 255));
oRange.SetFontSize(12);
// AutoFit Contents
oSheet.GetRange("E28").SetValue("AutoFit contents of this cell");
oSheet.GetCols("E").AutoFit(false, true);
//Columns("E").AutoFit
// Store the values in the range to the Array
var dirArray = oRange.GetValue();
oSheet.GetRange("A28").SetValue("Array size = " + dirArray.length + " x " + dirArray[1].length);
// Address
var oUsedRange = oSheet.GetUsedRange();
oSheet.GetRangeByNumber(oUsedRange.GetRows().Count, 0).SetValue("Used Range: " + oUsedRange.GetAddress());
oSheet.GetRangeByNumber(oUsedRange.GetRows().Count, oUsedRange.GetCols().Count).SetValue("Last Cell");
})();