Three UDFs

This post is in response to recent discussions at Daily-Dose-of-Excel where many and various worksheet formulas have been suggested to carry out tasks that are (it seems to me) better done with a simple User Defined Function (UDF):

Adding Every Other Cell (also at the Microsoft Office Blog: Adding Every Other Cell in a Column )
and
Summing the Digits of a Number

My solutions to these, and also another at Eng-Tips: Transposing data from columns, can be dowloaded here: Sum Tab.xls

The spreadsheet includes full open source code as usual:

SumSkip Function

SumSkip Function

The SumSkip function will sum every n’th row or column of a range, starting from any specified cell.


Function SumSkip(SumRange As Variant, Optional NumSkip _As Long _
= 2, Optional StartCell As Long = 1, _
Optional DirSkip As String) As Double
Dim Numrows As Long, NumCols As Long, Sums As Double
Dim i As Long, j As Long, k As Long
If TypeName(SumRange) = "Range" Then SumRange = SumRange.Value2
Numrows = UBound(SumRange)
NumCols = UBound(SumRange, 2)
If DirSkip = "" Then
If Numrows > NumSkip Then
DirSkip = "V"
ElseIf NumCols > NumSkip Then
DirSkip = "H"
End If
End If
DirSkip = UCase(DirSkip)
Select Case DirSkip
Case Is = "V"
For i = StartCell To Numrows Step NumSkip
For j = 1 To NumCols
Sums = Sums + SumRange(i, j)
Next j
Next i
Case Is = "H"
For j = StartCell To NumCols Step NumSkip
For i = 1 To Numrows
Sums = Sums + SumRange(i, j)
Next i
Next j
End Select
SumSkip = Sums
End Function

 

SumDig Function

SumDig Function

The SumDig function sums the digits of a value or string (either including or excluding values to the right of the decimal point).  I have incorporated the use of  a Byte array to extract the numeric characters without tripping over non-numeric characters, thanks to Charles Williams who provided a neat UDF in the DDoE thread using this technique.

Function SumDig(SumVal As String, _
Optional SumFract As Boolean = False) As Long
Dim NumDig As Long, i As Long, DPPos As Long, ByteA() As Byte
DPPos = InStr(1, SumVal, ".") * 2 - 1
ByteA = CStr(SumVal)
NumDig = Len(SumVal) * 2 - 1
If DPPos > 0 Then
For i = 0 To DPPos Step 2
SumDig = SumDig + Val(Chr(ByteA(i)))
Next i
If SumFract = True Then
For i = DPPos + 1 To NumDig Step 2
SumDig = SumDig + Val(Chr(ByteA(i)))
Next i
End If
Else
For i = 0 To NumDig Step 2
SumDig = SumDig + Val(Chr(ByteA(i)))
Next i
End If
End Function

Tabulate Function

Tabulate Function

The tabulate function creates a table based on row and column numbers and data listed in a 3 column range.  It was pointed out in the Eng-Tips thread that this could also be done with a pivot table, but the UDF solution seems simpler to me.

 

Function Tabulate(TabA As Variant) As Variant
Dim Numrows1 As Long, NumRows2 As Long, NumCols As Long, Tab2A() As Variant
Dim i As Long, j As Long
TabA = TabA.Value2
Numrows1 = UBound(TabA)
NumRows2 = TabA(Numrows1, 1)
NumCols = TabA(Numrows1, 2)
ReDim Tab2A(1 To Numrows1, 1 To NumCols)
For i = 1 To Numrows1
Tab2A(TabA(i, 1), TabA(i, 2)) = TabA(i, 3)
Next i
Tabulate = Tab2A
End Function

Does a straightforward UDF beat a convoluted worksheet function, or are UDFs best avoided?

What do you think?

Posted in Excel, UDFs, VBA | Tagged , , , , , | 8 Comments

Update to Publications

I have (at long last) updated my list of publications (all downloadable). Click on the link below to visit the site, or download direct from the list here.

My Publications

Here is the current list:

   
Predicting the Deflection of Concrete Structures in Practice (374 k Word file) Concrete Solutions 09, Sydney 2009
Predicting the Deflection of Concrete Structures in Practice presentation (1.4 MB Powerpoint file) Concrete Solutions 09, Sydney 2009
Efficient Analysis with the Strand7 API presentation (450 kB Powerpoint file) Concrete Institute of Australia seminar, Sydney 2009
Analysis and Design of Large Span Arch Structures under High Fills (1.1 MB Word file) Austroads Bridge Conference, Auckland 2009
Analysis and Design of Large Span Arch Structures under High Fills presentation (2.9 MB zipped Powerpoint file) Austroads Bridge Conference, Auckland 2009
Analysis and Design of Large Span Arch Structures under High Fills p (1.6 MB animation) Austroads Bridge Conference, Auckland 2009
Design of Robust Structures, presentation (1.3 MB pdf file) Concrete Institute of Australia seminar, Sydney 2009
Settlement of Precast Culverts Under High Fills; The Influence of Construction Sequence and Structural Effects of Longitudinal Strains (1.85 MB pdf file) Concrete Institute of Australia Conference, Adelaide 2007
Settlement of Precast Culverts Under High Fills; presentation (5.4 MB Powerpoint file) Concrete Institute of Australia Conference, Adelaide 2007
Finite element modelling of load shed and non-linear buckling solutions of confined steel tunnel liners (350 kB pdf file) ANZ Geomechanics Conference, Brisbane 2007
Finite element modelling of confined steel tunnel liners presentation (2.2 MB Powerpoint file) ANZ Geomechanics Conference, Brisbane 2007
Soil Loads On Cut And Cover Tunnels Under High Fills (3.9 MB Word file) Concrete Institute of Australia seminar, Sydney 2007
Soil Loads On Cut And Cover Tunnels Under High Fills, presentation (3.7 MB Powerpoint file) Concrete Institute of Australia seminar, Sydney 2007
High Performance Concrete in Bridges, durability and workability (800 kB MS Word file) Austroads Bridge Conference, Perth 2006
High Performance Concrete in Bridges presentation(2.6 MB MS Powerpoint file) Austroads Bridge Conference, Perth 2006
Prediction of Cracking and Deflections; International Code Provisions and Recent Research (920 kB Word file) Concrete Institute of Australia seminar, Sydney 2006
Prediction of Cracking and Deflections; presentations (1.4 MB Powerpoint file; 270 kB Powerpoint file) Concrete Institute of Australia seminar, Sydney 2006
High Strength Concrete in AS 5100 – Opportunities and Restrictions (360 kB Word file) Concrete Institute of Australia seminar, Sydney 2005
High Strength Concrete in AS 5100 – Presentation (1.8 MB Powerpoint file) Concrete Institute of Australia seminar, Sydney 2005
High Performance Concrete in Bridges (350 kB MS Word file) Concrete Institute of Australia Conference, Melbourne 2005
High Performance Concrete in Bridges presentation(1.8 MB MS Powerpoint file) Concrete Institute of Australia Conference, Melbourne 2005
North Kiama By-pass (6.1 MB MS Word file) Concrete Institute of Australia Conference, Melbourne 2005
North Kiama By-pass presentation(7.9 MB MS Powerpoint file) Concrete Institute of Australia Conference, Melbourne 2005
Soil Loads on Cut and Cover Tunnels Under High Fills (3.4 MB MS Word file) Australian Geomechanics Society Mini-symposioum, Sydney 2005
Soil Loads on Cut and Cover Tunnels Under High Fills presentation(3.9 MB MS Powerpoint file) Australian Geomechanics Society Mini-symposioum, Sydney 2005
Seismic design of Buried Structures to AS5100 (940 kB MS Word file) Australian Earthquake Engineering Society Conferenc, Mount Gambier 2004
Seismic design of Buried Structures to AS5100 presentation(2.0 MB MS Powerpoint file) Australian Earthquake Engineering Society Conferenc, Mount Gambier 2004
Design for Soil-Structure Interaction (2.8 MB MS Powerpoint file) Concrete Institute of Australia seminar, Sydney 2004
Bridge Deck Behaviour Revisited presentation(1.0 MB MS Powerpoint file) Austroads Bridge Conference, Hobart 2004
Bridge Deck Behaviour Revisited (190 kB MS Word file) Austroads Bridge Conference, Hobart 2004
Impact Loads on Buried Structures (300 kB MS Word file) Concrete Institute of Australia Conference, Brisbane 2003
Impact Loads on Buried Structures presentation(2.1 MB MS Powerpoint file) Concrete Institute of Australia Conference, Brisbane 2003
Morwell Tunnels -Design of a Buried Arch Culvert Under Very High Fill (640 kB MS Word file) Concrete Institute of Australia Conference, Brisbane 2003
Barcoo Outlet (300 kB MS Word file) Concrete Institute of Australia Conference, Perth 2001
Barcoo Outlet; presentation (2 MB MS Powerpoint file) Concrete Institute of Australia Conference, Perth 2001
Kwinnana Freeway (1.4 MB pdf file) Concrete Institute of Australia Conference, Perth 2001
Seismic Analysis of Buried Arch Structures World Conference on Earthquake Engineering, Auckland 2000
Homebush Bay Rail Link Concrete Institute of Australia Conference, Sydney 1999
Arch Structures (7 MB pdf file) Concrete Institute of Australia Conference, Sydney 1999
Arch Structures (text only) (0.18 MB doc file) Concrete Institute of Australia Conference, Sydney 1999
Arch Structures – (MS Powerpoint presenation, 5.1 MB file) Concrete Institute of Australia Conference, Sydney 1999
Non-linear Analysis of Buried Arch Structures Australasian Structural Engineering Conference, Auckland 1998
Analysis of Buried Arch Structure: Performance versus Prediction (Right click to download Word Document) Concrete Institute of Australia Conference, Adelaide 1997
Posted in Arch structures, Concrete, Geotechnical Engineering, Newton | Tagged , , , , | Leave a comment

Geometric Tools

I was recently sent a link to:

Geometric Tools Documentation

Which has a host of pdf files with detailed instructions on all manner of geometric calculations.  The focus of the site is animation for games programs, but there is plenty here of interest to engineers.

A small part of their listing is shown below (click for full size view):

GeometricTools

Posted in Coordinate Geometry, Maths, Newton | Tagged , | Leave a comment

LatPile – Analysis of Lateral Loads on Piles

This post presents an Excel User Defined Function (UDF) to carry out the analysis of vertical piles subject to horizontal loads, using the same approach as employed in the DOS program COM624. A spreadsheet including the UDF and an on-spreadsheet solution using the same method may be downloaded from LatPile.zip.  As usual the file contains full open source code for the UDF and associated routines.

Detailed background information on the method of analysis is given in the COM624 manual, which can be downloaded from the link given in the previous post.  An outline of the method, including all relevant equations used, is given below and in the download file, together with some simple examples.

The equations used in the analysis are shown in the screenshot below (click on any image for full size view):

LPile Finite Difference Equations

LPile Finite Difference Equations

 

On the FinDiff sheet of the download file these equations have been entered into a 25×25 matrix, which with the MINVERSE() and MMULT() functions allows the equations to be solved and the deflections calculated for any pile with 20 segments:

Finite Difference Equations in Matrix Format

Finite Difference Equations in Matrix Format

The same basic method of analysis has also been incorporated in a UDF, allowing the solution to be carried out much more conveniently and flexibly.  Input for the UDF is shown below:

LPile UDF

LPile UDF

Example 1 is a 20 m long pile of uniform stiffness in a uniform soil:

UDF Input and Results; Example 1

UDF Input and Results; Example 1

Example 1 Bending Moments

Example 1 Bending Moments

Example 1 Shear Forces

Example 1 Shear Forces

Example 1 Deflections

Example 1 Deflections

Example 2 is a reinforced concrete pile with a cracking moment of 60 kNm in a soil with stiffness increasing with depth. The pile and soil stiffness values have been adjusted by hand in this case. Future versions of the program will allow input of non-linear soil and pile section stiffness.

Example 2 Input and Results

Example 2 Input and Results

 

Example 2 Bending Moments

Example 2 Bending Moments

Example 2 Shear Forces

Example 2 Shear Forces

Example 2 Deflections

Example 2 Deflections

Posted in Beam Bending, Excel, Geotechnical Engineering, Newton, UDFs, VBA | Tagged , , , , , | 11 Comments

COM624 download and documentation sites

COM624 is a freeware DOS based program for the analysis of lateral loads on piles produced by the FHWA in the USA.  The program and documentation are available for free download, but are well hidden, so I’m posting links to the download sites here:

COM624 Program no longer available; see below

COM624 Manual

In coming posts I will post an Excel based pile lateral load analysis program, based on the same principles as COM624.

Update 10 Mar 2018:

The COM624 program is no longer available for free download, and the link to a commercial download is no loner active.

The link to the manual is still active.

The LatPilePY spreadsheet available here is still free, and provides most of the functionality of the COM624 program, with much friendlier input and output.  Download from the link, and see the Downloads or Downloads by category tabs for more information.

Posted in Geotechnical Engineering, Newton | Tagged , , | 11 Comments