+ Reply to Thread
Results 1 to 4 of 4

Woksheet Function "Slope" through VBA

  1. #1
    Registered User
    Join Date
    09-13-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    45

    Woksheet Function "Slope" through VBA

    I am having difficulty getting my VBA to run the worksheet function correctly. I have tried making all sorts of modifications with no luck. Below is an example of one of my many failed attempts. It reads fine down to the line were it calls the worksheetfunction.slope and spits out a "Run-time error '1004': Application-defined or object-defined error". I can get the function to work fine in the worksheet (Using "=SLOPE(Table1[@[-13.78]:[0.00]],1*Table1[[#Headers],[-13.78]:[0.00]]") but I need to call it through VBA and loop through the corresponding column and rows.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: Woksheet Function "Slope" through VBA

    First off, it is not WorksheetFunction.Slope - it is Application.WorksheetFunction.Slope.

    If it still doesn't work, then you may have an error returned, so change

    Dim mL As Double, mR As Double

    to

    Dim mL As Variant, mR As Variant

    and use

    If Not IsError(mL) Then

    And, I'm not sure why you are looping on j, or why you are using the same two ranges for your Slope parameters....
    Last edited by Bernie Deitrick; 03-17-2016 at 01:09 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,844

    Re: Woksheet Function "Slope" through VBA

    I cannot recreate the error. The code executes without error for me. Are you certain there is a sheet named "Graph" in the active workbook? Can you step through the code and identify which statement is triggering the error? Are any of the conditions that cause the SLOPE() function to return an error present?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    09-13-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Woksheet Function "Slope" through VBA

    Bernie
    I had the loop on j for additional code that needed to be looped column by column. I see what you are saying that it is not needed for the slope or linest function. I had both ranges the same until I got the script to run correctly, then I would modify appropriately.

    MrShorty
    The error populates at the line "mL = WorksheetFunction.Slope(XL, YL)". I am going to test Bernie's modifications and se if that works.

    Thank you both for the prompt response.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 01-15-2014, 08:53 AM
  2. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  3. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  4. [SOLVED] Variable "sheet-name" and "range-name" wanted in INDEX/MATCH-function
    By Fiebuls in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-01-2012, 04:09 PM
  5. Help on personalized "slope" function
    By excellina in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-19-2009, 06:02 PM
  6. [SOLVED] "Slope" and "intercept" function help
    By BGKeen629 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-04-2006, 02:25 PM
  7. [SOLVED] Please add a "sheet" function like "row" and "column" functions
    By Spreadsheet Monkey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2005, 12:15 PM
  8. [SOLVED] Replace "insert function" with "edit formula" button in fourmula b
    By 13brian in forum Excel General
    Replies: 0
    Last Post: 08-24-2005, 04:05 PM

Tags for this Thread

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