Method 'Color' of object 'Font' failed - excel

I'm getting the title error message in my Excel 2010 VBA code. I've looked at this question and this question which both look similar, but nether seems to address the issue.
My code parses through all the conditional formatting on the current worksheet and dumps it as text to another (newly created) worksheet - the ultimate goal is to load those same conditions to a nearly identical worksheet (thus I can't just copy the base worksheet).
The code is:
Public Sub DumpExistingRules()
'portions of the code from here: http://dailydoseofexcel.com/archives/2010/04/16/listing-format-conditions/
Const RuleSheetNameSuffix As String = "-Rules"
Dim TheWB As Workbook
Set TheWB = ActiveWorkbook
Dim SourceSheet As Worksheet
Set SourceSheet = TheWB.ActiveSheet
Dim RuleSheetName As String
RuleSheetName = SourceSheet.Name & RuleSheetNameSuffix
On Error Resume Next 'if the rule sheet doesn't exist it will error, we don't care, just move on
Application.DisplayAlerts = False
TheWB.Worksheets(RuleSheetName).Delete
Application.DisplayAlerts = True
On Error GoTo EH
Dim RuleSheet As Worksheet
Set RuleSheet = TheWB.Worksheets.Add
SourceSheet.Activate
RuleSheet.Name = RuleSheetName
RuleSheet.Range(RuleSheet.Cells(1, CellAddrCol), RuleSheet.Cells(1, OperatorCodeCol)).Value = Array("Cell Address", "Rule Type", "Type Code", "Applies To", "Stop", "Font.ColorRGB", "Formula1", "Formula2", _
"Interior.ColorIndexRGB", "Operator Type", "Operator Code")
Dim RuleRow As Long
RuleRow = 2
Dim RuleCount As Long
Dim RptCol As Long
Dim SrcCol As Long
Dim RetryCount As Long
Dim FCCell As Range
For SrcCol = 1 To 30
Set FCCell = SourceSheet.Cells(4, SrcCol)
For RuleCount = 1 To FCCell.FormatConditions.Count
RptCol = 1
Application.StatusBar = "Cell: " & FCCell.Address
PrintValue RuleSheet, RuleRow, CellAddrCol, FCCell.Address
PrintValue RuleSheet, RuleRow, RuleTypeCol, FCTypeFromIndex(FCCell.FormatConditions.Item(RuleCount).Type)
PrintValue RuleSheet, RuleRow, RuleCodeCol, FCCell.FormatConditions.Item(RuleCount).Type
PrintValue RuleSheet, RuleRow, AppliesToCol, FCCell.FormatConditions.Item(RuleCount).AppliesTo.Address
PrintValue RuleSheet, RuleRow, StopCol, FCCell.FormatConditions.Item(RuleCount).StopIfTrue
If FCCell.FormatConditions.Item(RuleCount).Type <> 8 Then
PrintValue RuleSheet, RuleRow, Formula1Col, "'" & Right(FCCell.FormatConditions.Item(RuleCount).Formula1, Len(FCCell.FormatConditions.Item(RuleCount).Formula1) - 1) 'remove the leading "=" sign
If FCCell.FormatConditions.Item(RuleCount).Type <> 2 And _
FCCell.FormatConditions.Item(RuleCount).Type <> 1 Then
PrintValue RuleSheet, RuleRow, Formula2Col, "'" & Right(FCCell.FormatConditions.Item(RuleCount).Formula2, Len(FCCell.FormatConditions.Item(RuleCount).Formula2) - 1) 'remove the leading "=" sign
End If
End If
RetryCount = 0
RetryColor:
PrintValue RuleSheet, RuleRow, FontColorCol, "'" & GetRGB(FCCell.FormatConditions(RuleCount).Font.Color)
PrintValue RuleSheet, RuleRow, IntColorIdxCol, "'" & GetRGB(FCCell.FormatConditions.Item(RuleCount).Interior.Color)
If FCCell.FormatConditions.Item(RuleCount).Type = 1 Then
PrintValue RuleSheet, RuleRow, OperatorTypeCol, OperatorType(FCCell.FormatConditions.Item(RuleCount).Operator)
PrintValue RuleSheet, RuleRow, OperatorCodeCol, FCCell.FormatConditions.Item(RuleCount).Operator
End If
RuleRow = RuleRow + 1
Next
Next
RuleSheet.Rows(1).AutoFilter = True
CleanExit:
If RuleRow = 2 Then
PrintValue RuleSheet, RuleRow, RptCol, "No Conditional Formatted cells were found on " & SourceSheet.Name
End If
On Error Resume Next
Set SourceSheet = Nothing
Set TheWB = Nothing
Application.StatusBar = ""
On Error GoTo 0
MsgBox "Done"
Exit Sub
EH:
If Err.Number = -2147417848 Then
MsgBox "Font.Color = " & FCCell.FormatConditions(RuleCount).Font.Color
If RetryCount < 5 Then
RetryCount = RetryCount + 1
Resume RetryColor
Else
MsgBox "RetryCount = " & RetryCount
Resume Next
End If
Else
MsgBox "Error Number: " & Err.Number & vbCrLf & _
" Description: " & Err.Description & vbCrLf & _
"Cell Address: " & FCCell.Address & vbCrLf
Resume Next
End If
End Sub
The line in question is the one immediately following the RetryColor: label. When that line of code is executed for a Unique Values conditional formatting rule (i.e. highlight duplicates), I get err.number = -2147417848' and err.description = "Method 'Color' of object 'Font' failed". The code drops to EH:, falls into the first IF statement, and displays the MsgBox without any problem.
Why is it that the statement FCCell.FormatConditions(RuleCount).Font.Color fails the first time, but executes perfectly the second time in the error handler? Once I've clicked the OK button on the MsgBox, execution resumes at the RetryColor: label, the statement executes correctly, and all is good.
To make sure this is clear, if I comment out the
MsgBox "Font.Color = " & FCCell.FormatConditions(RuleCount).Font.Color
line in EH:, the code will error 5 times without ever outputting the RGB code to my output worksheet, then continue on its way. If that line is in EH: (as shown above), I get the MsgBox and the .Font.Color will now be read in the main code and execution will continue as expected without error.
UPDATE: It seems that after letting this code sit for a week while I worked on something else, that it's now slightly more broken. In the error handler, I now get the titular error message popping, up. If I hit F5, it will execute and display the MsgBox with the color code.
So now, it will fail twice, then execute properly the 3rd time.
For completeness, here's the code for GetRGB:
Private Function GetRGB(ByVal ColorCode As Variant) As String
Dim R As Long
Dim G As Long
Dim B As Long
If IsNull(ColorCode) Then
GetRGB = "0,0,0"
Else
R = ColorCode Mod 256
G = ColorCode \ 256 Mod 256
B = ColorCode \ 65536 Mod 256
GetRGB = R & "," & G & "," & B
End If
End Function
I have to pass the parameter as a Variant because when the .Font.Color is set to Automatic in the color chooser, I get a NULL returned, thus the If statement in GetRGB.
Another Update: After letting this code sit for a few more weeks (it's to make my life easier, not an official project, therefore it's at the bottom of the priority list), it seems that it will generate the error on every call now, instead of just sometimes. However, the code will execute properly in the immediate window!
The yellow highlighted line is the one that generated the error, yet you can see the results in the immediate window.
Also (I realize this should really be another question), if anybody happens to quickly see any reason for the SourceSheet.Activate line, please let me know - I was getting random errors without it, so I put that in. Usually these errors are because of unqualified references working on the currently active sheet (which would be RuleSheet as soon as it's created), but I thought I had all my references qualified. If you see something I missed, please pipe up! Otherwise, I'll probably head over to CodeReview to have them take a look at what I missed once I get this working properly.

I think I've reduced this to a root cause.
I manually added 2 different types of FormatConditions in cell Sheet1.A1:
And here's my code, in the same workbook.
Sub foo()
Dim rng As Range
Set rng = Sheet1.Range("A1")
Dim fc As Object
On Error Resume Next
Sheet2.Activate
Set fc = rng.FormatConditions(1)
Debug.Print ActiveSheet.Name, TypeName(fc), fc.Type
Debug.Print , fc.Font.Color
Set fc = rng.FormatConditions(2)
Dim fnt As Font2
Debug.Print ActiveSheet.Name, TypeName(fc), fc.Type
Debug.Print , fc.Font.Color
Sheet1.Activate
Set fc = rng.FormatConditions(1)
Debug.Print ActiveSheet.Name, TypeName(fc), fc.Type
Debug.Print , fc.Font.Color
Set fc = rng.FormatConditions(2)
Debug.Print ActiveSheet.Name, TypeName(fc), fc.Type
Debug.Print , fc.Font.Color
End Sub
And here's the output:
Sheet2 FormatCondition 1
3243501
Sheet2 Top10 5
Sheet1 FormatCondition 1
3243501
Sheet1 Top10 5
13998939
So the FormatConditions.Item method will not always return a FormatCondition
I can't reproduce your Immediate Window behavior, so maybe you inadvertently activated the sheet?
If I remove the On Error Resume, and break at the error for the Top10.Font.Color call, and then query in the debug window, I get:
Run-time error '-2147417848 (80010108)':
Automation error
The object invoked has disconnected from its clients.
For which Google takes me to Error or Unexpected Behavior with Office Automation When You Use Early Binding in Visual Basic
Based on my results, when the FormatConditions.Item returns a Top10 (and maybe other types, including your UniqueValues type), it isn't possible to access the Font.Color property unless the range's sheet is active.
But it looks like you have it active? I wonder if you're changing the active sheet in PrintValue?

Regarding your second question:
I have always have had problems with setting cells that are not in an active sheet, the most probable cause for the problem in doing SourceSheet.Activate relies on the fact of the Set range later:
Set FCCell = SourceSheet.Cells(4, SrcCol)
I've found that, if the sheet is not active, it would fail within the cells() argument, I think the best approach for this is using Range before Cells.
This may be the case.
So for this example I would do something like:
With SourceSheet:Set FCCell = .Range(.Cells(4,SrcCol):End With

Related

Selenium Webdriver VBA - New Loop for Error

Goodnight
I would like some help if possible. I'm putting this code together, but I'm not able to create an output if it doesn't find the page item. I would like if he doesn't find the intem he would go to the next line, not displaying an error message as I have a lot of data to capture.
Dim drive As New Selenium.ChromeDriver
Dim ks As Selenium.Keys
Dim tempo As Integer
Set ks = New Selenium.Keys
site = "http://www.google.com"
Plan1.Select
tell = Range("A" & Rows.Count).End(xlUp).Row
Line = 4
drive.Start
drive.Get site
Do Until Cells(Linha, 1) = ""
For Line = 4 To tell
Number = Range("A" & Linha).Value
drive.SwitchToFrame drive.FindElementById("WIDGET_ID_4")
Set telephone = drive.FindElementByXPath("/html/body/.........")
Range("B" & Line).Value = telephone.Attribute("outerText")
drive.SwitchToDefaultContent
Next Linha
Loop
drive.Quit
MsgBox "Process Ok"
End Sub```
Within the loop, test if the tab is found i.e. if not tab is nothing then do stuff.....else move to next id. Wrap the SET line in an On Error Resume Next On Error GoTo 0 pair to suppress potential element not found exception.
I think linha should be line and Number be used to set the next id.
Please do note that using unqualified ranges e.g. Range without specifying the worksheet, you are implicitly referencing the current ActiveSheet and this is bug-prone.
Do Until Cells(Line, 1) = vbNullString
For Line = 4 To tell
Number = Range("A" & Line).Value
Dim targetTab As webElement
On Error Resume Next 'suppress potential exception
Set targetTab = drive.FindElementById("WIDGET_ID_4")
On Error GoTo 0 'switch exception raising back on
If Not targetTab Is Nothing Then 'test if reference obtained for target element
drive.SwitchToFrame targetTab
Set telephone = drive.FindElementByXPath("/html/body/.........")
Range("B" & Line).Value = telephone.Attribute("outerText")
drive.SwitchToDefaultContent
Set targetTab = Nothing
End If
Next Line
Loop

Application crashes when ComboBox1 of 2 changes value - ComboBox1 change event

I'm a VBA NewBe (this is my first post asking a question on any VBA help site) working on a Property/Expense Management application in excel. the ComboBoxes in question are used to select worksheets based on a Property ID, propID, in cmbPropID based on a range in a "Control" worksheet and the worksheet year, wsYr, in cmbYear determined by the individual propID's beginning year, wsStartYr, and the current calendar year, wdCurYear. I am able to select/activate and view all worksheets of the first property I select. However, when I select another property to work on the application crashes with Debug error: 9 - Script out of range! I have been going blind for over a week searching for a solution without success.
This issue is important in the overall functionality of the application. I hope someone is able to help me with this. Thanks in advance.
Below are the code sections for the ComboBoxes
The first configures cmbPropID
'this is an excert form MultiPage1
Case 2
'configure cmbPropID DDL
wkstControl.Activate
selectedRow = cmbPropID.ListIndex + 3 'I presume this is 3 instead of 2 because when using 2
'this throws an error - not sure why
For Each cPart In wsCntrl.Range(Range("propIDs"), Range("A" & Rows.Count).End(xlUp))
pAct = wsCntrl.Cells(selectedRow, 11).Value 'Value used to test the "isActive" status of a RealEstate property location
With Me.cmbPropID
If pAct = True And cPart.Value <> "" Then cmbPropID.AddItem cPart.Value 'Never Shows pAct as False ???
'this presents an issue that if is inActive of does'nt have worksheets it causes
' Debug error "Error: 13, Type Mismatch"
End With
Next cPart
This sub configures the contents of the cmbYears DDL and should reset the DDL's contents when selection a different propID ... see notes in next sub-routine
Private Sub cmbPropID_Change()
Dim i
Dim strValue As String
wsCntrl.Activate
pID = ""
wsA = ""
wsYr = ""
selectedRow = cmbPropID.ListIndex + 2
wsStartYr = wsCntrl.Cells(selectedRow, 13).Text
With cmbYears
.Clear
For i = wsStartYr To wbCurYear
pAct = wsCntrl.Cells(selectedRow, 11).Value
If wbCurYear <> wsStartYr And pAct = True Then
.AddItem i
ElseIf wbCurYear = wsStartYr Then
.AddItem wbCurYear
End If
Next i
End With
lstDsplyUtil1.RowSource = ""
pID = cmbPropID.Text
End Sub
and finally, cmbYears. The code crashes at Set wsUtil = Worksheets(wsA) when a when cmbPropID changes.
Private Sub cmbYears_Change()
wsYr = cmbYears.Text
wsA = pID & "_" & wsYr
Debug.Print pID, wsYr, wsA
Set wsUtil = Worksheets(wsA)
lstDsplyUtil1.RowSource = wsA & "!$A$5:$Y$16"
Debug.Print pID, wsYr, wsA
'Remove after testing
Label120.Caption = wsA
Label136.Caption = pID
Label138.Caption = wsYr
Label134.Caption = lstDsplyUtil1.RowSource
wsUtil.Activate
End Sub
I went back to troubleshooting the Crash Issue after posting my Question. I developed the habit of creating Labels on the various UserForms, assigned their .Caption value equal to the the various Variable values, and used Debug.Print to track those Values in the Immediate Window.
What I noticed was that when Debug threw its Error the Immediate Window showed the new pID Value after the cmbPropID_Change() Event to be the same as BEFORE the cmbPropID_Change Event and the cmbPropID.ListIndex = -1 when it should have been >=0 depending on the selection in cmbPropID. This lead me think that the problem was with the cmbPropID_Change() Event configuration. However, no matter what changes I made to the cmbPropID_Change() Event configuration the issue remained.
I began looking at the cmbYears_Change() Event configuration where the Error happens and it occurred to me that I could pre-Trap and thereby avoid the Error by encapsulating cmbYears_Change() code in a set of If Then ElseIf statements like this:
If cmbYears.ListIndex <> -1 Then
'cmbYears' original code
ElseIf cmbYears.ListIndex >= 0 Then
'cmbYears' original code
End If
This worked perfectly and this is the final code!
Private Sub cmbYears_Change()
If cmbYears.ListIndex <> -1 Then
pID = cmbPropID.Text
wsYr = cmbYears.Text
wsA = pID & "_" & wsYr
lstDsplyUtil1.RowSource = wsA & "!$A$5:$Y$16"
Debug.Print pID, wsYr, wsA
Set wsUtil = Worksheets(wsA)
wsUtil.Select
ElseIf cmbYears.ListIndex >= 0 Then
pID = cmbPropID.Text
wsYr = cmbYears.Text
wsA = pID & "_" & wsYr
lstDsplyUtil1.RowSource = wsA & "!$A$5:$Y$16"
Debug.Print pID, wsYr, wsA
Set wsUtil = Worksheets(wsA)
wsUtil.Select
End If
End Sub
Issue Resolved!

Assigning Macro with ParamArray: Formula is Too Complex to add to the Object

I have a macro (below) that inserts a new row into an un-defined number of Named ranges using ParamArray, it works fine except for when I try to assign the macro with more than 5-6 arguments I get a message box that says "Formula Too Complex to Assign To Object" (see picture above)
(see assignment string below)
'InsertNewRow "ServiceCrewDay_EmployeeList", "SAP_SCD_InPool", "SAP_SCD_OutPool", "SAP_SCD_SecondaryIn", "SAP_SCD_SecondaryOut", "SAP_SCD_ORD","SAP_SCD_THF","SAP_SCD_LH", "SAP_SCD_LH"'
Macro:
Sub InsertNewRow(ParamArray args() As Variant)
Dim ans: ans = MsgBox("WARNING: " & vbNewLine _
& "Action Cannot be undone!" & vbNewLine & "Continue?", vbYesNo, "Warning!")
If ans = vbNo Then: Exit Sub
Call HaltOperations
Call ActiveSheet.Unprotect()
Call Sheets("SAP Timesheet").Unprotect()
On Error GoTo OnError_Exit
'Loop and Check All Named Ranges Exist Before Proceeding
For Each a In args
If RangeExists(a) = False Then
MsgBox ("Named Range: " & a & " Not Defined!" & vbNewLine & "Operation Cancelled")
Exit Sub
End If
Next a
Dim rng As Range
'ADD ROW TO EACH NAMED INPUT RANGE
For Each a In args
Set rng = Range(a)
With rng
.Rows(.Rows.count).EntireRow.Insert
.Rows(.Rows.count - 2).EntireRow.Copy
.Rows(.Rows.count - 1).EntireRow.PasteSpecial (xlPasteFormulasAndNumberFormats)
On Error Resume Next: .Rows(.Rows.count - 1).EntireRow.PasteSpecial (xlPasteFormats)
End With
Next a
On Error GoTo OnError_Exit
'ADJUST HEIRACHY NUMBERS ON FIRST INPUT RANGE (MANNING TAB)
Set rng = Range(args(0))
Dim col As Integer
col = rng.Column
Cells(rng.Row + rng.Rows.count - 2, col).Offset(0, -1).Value _
= Cells(rng.Row + rng.Rows.count - 3, col).Offset(0, -1).Value + 1
Cells(rng.Row + rng.Rows.count - 1, col).Offset(0, -1).Value _
= Cells(rng.Row + rng.Rows.count - 3, col).Offset(0, -1).Value + 2
Call ResumeOperations
Application.CutCopyMode = False
Call ActiveSheet.Protect()
Call Sheets("SAP Timesheet").Protect()
Exit Sub
OnError_Exit:
Call ResumeOperations
Application.CutCopyMode = False
Call ActiveSheet.Protect()
Call Sheets("SAP Timesheet").Protect()
End Sub
Private Function RangeExists(rng As Variant) As Boolean
Dim Test As Range
On Error Resume Next
Set Test = Range(rng)
RangeExists = Err.Number = 0
End Function
Private Sub HaltOperations()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
End Sub
Private Sub ResumeOperations()
ResumeOps:
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
End Sub
The Macro itself runs as expected it's just the assigning the named ranges that is causing the issue.
is there a better way to do this?
or is there a way to get around the Formula is too complex method?
and if there is will that need to be done on all end user pc's or just on mine and the settings will carry over?
What I have thought about doing was just taking in 2 Named ranges and then for the following ranges Just offsetting those by the Row Count of the previous range so if Range2 = Sheets().Range("A1:A10") then Range3 = Range2.Offset(Range2.Rows.Count,0) then the assingment input would only need to be Range1 as string, Range2 as string, NumberOfExtraRanges as integer the reason I need atleast two ranges is because every range after range 1 is on a different tab and is essentially a raw data version of all pay info hours etc. in the first tab which will be Range1_EmployeeList
which I will play around with while I wait for a response.
TIA
Not a Complete answer but I did find that inside the ParamArray I could just assign One Input Range using a , to seperate each defined range. I haven't tested the limitations doing it this way but it does seem to atleast let me use a few extra inputs.
Example (Not Working):
Note: Each Defined Range is a Separate Input
'InsertNewRow "ServiceCrewDay_EmployeeList", "SAP_SCD_InPool" ," SAP_SCD_OutPool","SAP_SCD_SecondaryIn", "SAP_SCD_SecondaryOut"'
Example (Working):
Note Each Defined Range is passed as 1 input
'InsertNewRow "ServiceCrewDay_EmployeeList", "SAP_SCD_InPool, SAP_SCD_OutPool,SAP_SCD_SecondaryIn,SAP_SCD_SecondaryOut"'

Return to a certain routine when an IF condition is not met

Facing an issue with coming up with a way to send back my code to a certain place when an IF condition is not met. In the code below, I have included an input box requiring data to be entered however through an IF condition I want to make sure atleast 8 digits are entered, If less than 8 digits are entered then I want to show a msg box "Error" and return to GL_Code position asking user to fill the inputbox again.
Dim GL_CY As Variant
Dim GL_Book As Workbook
GL_CY = Application.GetOpenFilename(Title:="Open GL", FileFilter:="Excel Files (*.xls*),*xls*")
Set GL_Book = Application.Workbooks.Open(GL_CY)
'Filtering Range
Dim GL_Code As Variant, GL_Rng As range, GL_LR As Long
Dim GL_Sheet As Worksheet
Set GL_Sheet = GL_Book.Worksheets(1)
GL_LR = GL_Sheet.range("B" & Rows.Count).End(xlUp).Row
GL_Code = Application.InputBox(Prompt:="Enter GL code to generate its activity ", Title:="Generate GL Activity", Type:=1)
If VBA.IsError(GL_Code) Then
GoTo ErrorHandle
ElseIf Len(GL_Code) < 8 Then
MsgBox "GL Code Not Entered", , "Error"
'Return To GL_Code
End If
Set GL_Rng = GL_Sheet.range("A4:R" & GL_LR).CurrentRegion.Offset(3, 0)
Relevant part of the issue is (Need a code for the commented part at the last line)
GL_Code = Application.InputBox(Prompt:="Enter GL code to generate its activity ", Title:="Generate GL Activity", Type:=1)
If VBA.IsError(GL_Code) Then
GoTo ErrorHandle
ElseIf Len(GL_Code) < 8 Then
MsgBox "GL Code Not Entered", , "Error"
'Return To GL_Code
Naqi,
This should do the trick, at least it worked on my machine. I had to put a phony ErrorHandle label in as you didn't show that in your code.
Option Explicit
Sub Test()
Dim GL_Code As String
Dim GoodEntry As Boolean
GoodEntry = False
Do
GL_Code = Application.InputBox(Prompt:="Enter GL code to generate its activity ", Title:="Generate GL Activity", Type:=1)
If (GL_Code = False) Then Exit Sub 'User pressed CANCEL!
If VBA.IsError(GL_Code) Then
GoTo ErrorHandle
Else
If Len(GL_Code) < 8 Then
MsgBox "GL Code Not Entered", , "Error"
'Return To GL_Code
Else
GoodEntry = True
End If
End If
Loop Until GoodEntry
ErrorHandle:
End Sub
HTH

My VBA Excel function works when called by a test function but consitently fails when called from sheet another function that is a embedded in a cell

Public Sub addtoMA(dbPrice As Double, dbRow As Double, sh As Worksheet)
Dim s As Long 'for bitshifting the array
Const colstosave = 50
Dim rn As Range, intPrice() As Variant
deActsheet 'stop events and other annoyance
On Error GoTo catch
If dbRow = 0 Then
'MsgBox "row number missing in addtoma"
GoTo finally
End If
Set rn = sh.Range("At" & dbRow & ":cQ" & dbRow) 'the row
intPrice() = rn 'the array
' shift elements one position right- e.g. arr 99 moves to arr 100
For s = colstosave To 2 Step -1
If intPrice(1, s - 1) <> "" Then
intPrice(1, s) = intPrice(1, s - 1)
Else
intPrice(1, s) = 0
End If
Next s
intPrice(1, 1) = dbPrice 'current price
rn = intPrice() 'store the array
finally:
Set rn = Nothing
actSheet 'allow events and other annoyance
Exit Sub
catch:
'MsgBox Err.Description
Debug.Print ""
GoTo finally
End Sub
The code above runs perfectly when I call form the immediate window with:
addtoMA 5,9,sheetpointer
in integration it is called by a function that is embedded as a formula.
The parameters the are receibed are identical I double checked this.
rn.rows and rn.columns.count are exactly the same dimensions as
ubound(intprice,1) and ubound(intprice,2)
Yet every time it is called from the sheet it fails with
Application-defined or object-defined error
I could just use a database, but I cant be beaten by this.
Any ideas?
It just generates a few moving averages for a bot

Resources