Posted on March 14, 2008 by dougaj4
The technique for calculating section properties from coordinates is conveniently coded into a UDF:
Function Area(xy_range As Variant) As Double
Dim XYcells As Variant
Dim N As Long, NumX As Long
Dim XD As Double, YSum As Double
XYcells = GetArray(xy_range)
NumX = UBound(XYcells, 1) - LBound(XYcells, 1) + 1
If NumX < 3 Then
XYcells = Transpose1(XYcells)
NumX = UBound(XYcells, 1) - LBound(XYcells, [...]
Filed under: Arrays, Charts, Excel, UDFs | Tagged: Section Properties; Area; First Moment of Area; Second | No Comments »
Posted on March 5, 2008 by dougaj4
Yesterday we looked at how to get data from a worksheet range into a VBA array. Today’s post looks at the opposite operation; writing an array to a worksheet range.
With a UDF it couldn’t be simpler:
Function MyFunction() as Variant
Dim MyArray() as double
…
MyFunction = MyArray
End Function
This function will return whatever was in MyArray. To access all [...]
Filed under: Arrays, Excel, UDFs | No Comments »
Posted on March 4, 2008 by dougaj4
Transferring data from a worksheet into a VBA routine, or the other way round, is one of the most frequent tasks carried out in VBA programming. Fortunately there is a simple way to do it:
In a subroutine:
Name the data range in the spreadsheet
Declare a variant variable in the VBA code
Variable = Rangename.value
Dim DataArray as Variant
DataArray [...]
Filed under: Arrays, Excel, UDFs | Tagged: Array, GetArray, UDF, VBA | 1 Comment »