• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Unit 7: Built-In Functions
 

Unit 7: Built-In Functions

on

  • 636 views

 

Statistics

Views

Total Views
636
Views on SlideShare
620
Embed Views
16

Actions

Likes
0
Downloads
11
Comments
0

2 Embeds 16

https://olangel.embanet.com 11
http://olangel.embanet.com 5

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Unit 7: Built-In Functions Unit 7: Built-In Functions Presentation Transcript

    • Excel Macros Level 1
      Built-in Functions and Statements
    • Built-in Functions
      VBA has large number built-in functions and statements
      Some are shown in Table 7-1 (p. 78) and Table 7-2 (p. 80)
      4/29/2010
      M. Campbell - 2010
      2
      p. 78
    • Procedure Template
      SubChangeFormat(FontName [, FontSize])
      Parameters listed in italics
      Optional parameters listed in [square brackets]
      Type declarations will be listed separately
      4/29/2010
      M. Campbell - 2010
      3
      p. 78
    • MsgBox
      MsgBox(prompt [, buttons] [, title])
      prompt (String)
      Message to display in body
      buttons (Long)
      Sum of values to specify properties of message box
      See Table 7-2 for enum of argument values
      title (String)
      Message to display in title bar
      4/29/2010
      M. Campbell - 2010
      4
      p. 78
    • MsgBox
      MsgBox function returns number indicating which button pressed
      Defined as VbMsgBoxResult enumerator
      See Table 7-3 for return values
      4/29/2010
      M. Campbell - 2010
      5
      p. 78
    • Activities
      In the Unit 7 Activities complete:
      Activity 1: MsgBox Procedure
      4/29/2010
      M. Campbell - 2010
      6
    • InputBox
      InputBox(prompt[, title] [, default])
      prompt (String)
      Message to display
      title (String)
      Message to display in title bar
      default (String)
      Default value for the text box
      4/29/2010
      M. Campbell - 2010
      7
      p. 81
    • InputBox
      Returns the string the user enters in text box
      title (String)
      Message to display in title bar
      default (String)
      Default value for the text box
      4/29/2010
      M. Campbell - 2010
      8
      p. 81
    • Activities
      In the Unit 7 Activities complete:
      Activity 2: InputBox Subroutine
      4/29/2010
      M. Campbell - 2010
      9
    • VBA String Functions
      Please review pages 82-84 especially:
      Len
      UCase and LCase
      Left, Right, and Mid
      Str and Val
      Trim, LTrim, and RTrim
      4/29/2010
      M. Campbell - 2010
      10
      p. 82
    • Activities
      In the Unit 7 Activities complete:
      Activity 3: Phone Number Processing
      4/29/2010
      M. Campbell - 2010
      11
    • The Is Functions
      IsDate
      Returns true if variable is a date
      IsEmpty
      Returns true if variable is empty
      IsNull
      Returns true if variable is Null
      IsNumeric
      Returns true if variable is a numeric type
      4/29/2010
      M. Campbell - 2010
      12
      p. 85
    • Immediate If Function
      IIf(Expression, TruePart, FalsePart)
      If Expression is True returns TruePart
      If Expression is False returns FalsePart
      Always evaluates both parts
      Can lead to errors if one part should not be evaluated
      4/29/2010
      M. Campbell - 2010
      13
      p. 85
    • Switch Function
      Switch(expr1, value1, expr2, value2, _
      … , exprn, valuen)
      When it finds an expression that matches it returns the corresponding value
      If no match is made returns Null
      4/29/2010
      M. Campbell - 2010
      14
      p. 86
    • Dim number As Variant
      Dim check As Integer
      number = Switch(check = 1, "one", _
      check = 2, "two", _
      check = 3, "three")
      If Not IsNull(number) Then
      Debug.Print(number)
      Else
      Debug.Print("Unrecognized number")
      End If
      4/29/2010
      M. Campbell - 2010
      15
    • Units Conversion
      InchesToPoints(inchValue)
      PointsToInches(pointValue)
      Many Excel functions take values in points
      May prefer to work in inches
      72 points in an inch
      4/29/2010
      M. Campbell - 2010
      16
      p. 87
    • Handling Errors
      VBA has methods to handle run-time errors
      Error handling is vital in applications meant for public release
      4/29/2010
      M. Campbell - 2010
      17
      p. 88
    • On Error Goto
      On Error GotoLabel
      If a run-time error occurs VBA will goto the code following the label
      4/29/2010
      M. Campbell - 2010
      18
      p. 88
    • On Error Resume Next
      On Error Resume Next
      VBA will continue executing code immediately following line that caused error
      4/29/2010
      M. Campbell - 2010
      19
      p. 90
    • Resume Statement
      Resume
      Resume with line that caused error
      Good if your code corrected the error
      Resume Next
      Resume with the line after the one that caused error
      Resume label
      Resume with code at line labelled label
      4/29/2010
      M. Campbell - 2010
      20
      p. 91