Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 1
Default VBA - function doesn't calculate unless clicked on

Hi all

I have written a function in vba (I am pretty new to vba). It takes two arrays and finds the gradient. You also have two inputs to remove points from the beginning or end. It works exactly how I want it to except when I changed from the dependant cell (cut min and max) being on the same sheet to being on a new sheet and then changed the contents of these cells the function returns a #value! error.

when i click on the function within the worksheet (in the formula bar) and press enter the function suddenly works fine again.

Is there an autocalculate property which needs to be enabled or something?

Thanks

Danny

code below:

Public Function myGradient(lngMinRow As Long, InputColumn As String, lngCutRows As Long)


'declare variables
Dim xArray, yArray, lngMaxRow As Long

'define variables
lngMaxRow = 79 - lngCutRows

ReDim xArray(1, lngMaxRow - lngMinRow)
xArray = Range(InputColumn & lngMinRow, InputColumn & lngMaxRow)

ReDim yArray(1, lngMaxRow - lngMinRow)
yArray = Range("A" & 89, "A" & 89 + lngMaxRow - lngMinRow)


'gradient calculation
myGradient = Application.WorksheetFunction.Slope(xArray, yArray)


End Function
  #2   Report Post  
Junior Member
 
Posts: 1
Default

Hi this might help put you on the right track
Quote:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clicked NO to save, should have clicked YES Jenn Excel Discussion (Misc queries) 1 March 8th 10 09:04 PM
Function Arguments dialog vanishes when clicked an inserted shape RK Excel Worksheet Functions 2 February 2nd 09 07:58 AM
function doesn't calculate [email protected] Excel Worksheet Functions 3 December 18th 06 04:26 AM
Change cell value when right-clicked/double-clicked grime[_5_] Excel Programming 5 October 17th 05 01:52 PM
Function Won't Calculate -- Sometimes Bill Martin -- (Remove NOSPAM from address) Excel Discussion (Misc queries) 4 April 13th 05 04:38 PM


All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"