+ Reply to Thread
Results 1 to 3 of 3

Excel function in VBA

Hybrid View

secondrate Excel function in VBA 07-08-2010, 06:10 AM
royUK Re: Excel function in VBA 07-08-2010, 06:20 AM
secondrate Re: Excel function in VBA 07-08-2010, 08:44 AM
  1. #1
    Registered User
    Join Date
    06-23-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2010/2007
    Posts
    34

    Excel function in VBA

    Hi guys, I'm trying to call the function "mduration" in VBA. It outputs the correct numbers but it always says: "type mismatch" after performing the calculations.

    Here's the code:

    
    
    Cell.Offset(0, 15).Formula = "=mduration(" & Chr(34) & Date & Chr(34) & ", " & Chr(34) & Cell.Offset(0, 6).Value & Chr(34) & ", " & Chr(34) & Cell.Offset(0, 4).Value / 100 & Chr(34) & ", " & Chr(34) & Cell.Offset(0, 14).Value / 100 & Chr(34) & ", " & Chr(34) & Cell.Offset(0, 5).Value & Chr(34) & ")"
    Cell.offset(0,14).value refers to yield. It has the following code which works fine:

    Cell.Offset(0, 14).Formula = "=yield(" & Chr(34) & Date & Chr(34) & ", " & Chr(34) & Cell.Offset(0, 6).Value & Chr(34) & ", " & Chr(34) & Cell.Offset(0, 4).Value / 100 & Chr(34) & ", " & Chr(34) & Cell.Offset(0, 12).Value & Chr(34) & "," & Chr(34) & 100 & Chr(34) & "," & Chr(34) & Cell.Offset(0, 5).Value & Chr(34) & ")*100"
    Cell.Offset(0, 14).Value = Cell.Offset(0, 14).Value
    Any suggestions as to how to combat the type mismatch error?
    Last edited by secondrate; 07-08-2010 at 10:39 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Excel function in VBA

    Do you want the result in the cell?
    [code]
    Cell.Offset(0, 15).Value=application.WorksheetFunction.MDuration(etc
    [/code
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-23-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2010/2007
    Posts
    34

    Re: Excel function in VBA

    hmm, i'll try that but would you know why my code is producing an error?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1