Presentation is loading. Please wait.

Presentation is loading. Please wait.

ME 142 Engineering Computation I Using Excel Arrays in Functions.

Similar presentations


Presentation on theme: "ME 142 Engineering Computation I Using Excel Arrays in Functions."— Presentation transcript:

1 ME 142 Engineering Computation I Using Excel Arrays in Functions

2 Key Concepts Using Excel Arrays in Functions

3

4  Techniques used earlier in the class for matrices may also be used to pass array information to and from a function.  This effectively allows a function to return information to more than a single cell.

5 Using Excel Arrays in Functions Function AddVect(V1, V2) 'Adds two 2-dimensional vectors Dim AV(1 To 2) AV(1) = V1(1) + V2(1) AV(2) = V1(2) + V2(2) AddVect = AV End Function

6 Example Problem  Develop a function to subtract two 3- dimensional vectors

7 Example Problem Function VDiff(v1, v2) Dim Results(1 To 3) If v1.Count <> 3 Or v2.Count <> 3 Then MsgBox (“Error-each vector must contain 3 cells") Else For i = 1 To 3 Results(i) = v1(i) - v2(i) Next i VDiff = Results End If End Function

8 Tips for Using Excel Arrays in Functions Use one array variable for each vector Vector arrays are passed to function via argument list Do NOT dimension argument list variables May use.Count method to determine vector size Dim output array to store results DO dimension output array variable Set output array equal to function name to return results Select entire output area in spreadsheet before launching Use Ctrl+Shift+Enter

9 Homework Help ‘n Hints


Download ppt "ME 142 Engineering Computation I Using Excel Arrays in Functions."

Similar presentations


Ads by Google