Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 11th, 2008, 01:58 PM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error setting Range Value property

Hi

I have a procedure which performs various calculations and writes a calculated value to a cell within a loop. For some reason the procedure will get so far before displaying the runtime error: -2147417848 (80010108) Method 'Value' of object 'Range' failed.

The error occurs when trying to set the range's value property. This seems to happen at a random iteration in the loop within the procedure.

The range is valid since I can access it's other properties (e.g. address), and I can read the current value of the cell also. The value I am attempting to write to the cell is also perfectly valid and no different (in terms of decimal places or size) to the current value of the cell.

Now this is where it gets weirder! While in debug mode, if I attempt to set the cell's value via the immediate window, I get the following error: -2147417848 (80010108) Automation error The object invoked has disconnected from its clients.

At this point, Excel gets itself into a state where, if I'm in a worksheet and hit F9 to calculate, Excel crashes!

I simply do not understand why this is happening. There's nothing 'rocket science' about what I'm trying to do. I'm working with some of Excel's most basic objects as I have done since I started doing VBA some years ago! This error seems to randomly happen. Sometimes, the procedure will complete without ANY errors!

Apologies for my tone, but I am very frustrated with Excel at the moment. I would be sincerely grateful if anyone can offer any insight into this. FYI, I am using Excel 2007.

Much Appreciated!

Keith

 
Old March 12th, 2008, 12:04 PM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Below is the procedure, which is essentially a bi-section method. The bold lines are where the error happens. I figure the more info I give, the more likely someone will be able to help.

Sub RunSeek(wks As Worksheet)

    Dim i As Integer
    Dim benchmark As Double
    Dim Tolerance As Double
    Dim RequiredRuns As Double
    Dim LowGuess As Double
    Dim HighGuess As Double
    Dim MidGuess As Double
    Dim MidAns As Double
    Dim MagErr As Double

    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False

    benchmark = Timer
    Tolerance = 0.001

    For i = 0 To 10
        If wks.Cells(5 + i, 2) = 0 Then
            wks.Cells(5 + i, 7) = 0
        Else
            RequiredRuns = wks.Cells(5 + i, 2)
            LowGuess = 1 - 1 / wks.Cells(5 + i, 5)
            HighGuess = 1
            MidGuess = (LowGuess + HighGuess) / 2
            wks.Cells(5 + i, 7).Value = MidGuess
            wks.Range(wks.Name & "CalcRange" & i + 1).Calculate
            MidAns = wks.Cells(5 + i, 8)
            MagErr = Abs(RequiredRuns - MidAns)

            Do Until MagErr < Tolerance
                If MidAns < RequiredRuns Then
                    LowGuess = MidGuess
                Else
                    HighGuess = MidGuess
                End If

                MidGuess = (LowGuess + HighGuess) / 2
                wks.Cells(5 + i, 7).Value = MidGuess
                wks.Range(wks.Name & "CalcRange" & i + 1).Calculate
                MidAns = wks.Cells(5 + i, 8)
                MagErr = Abs(RequiredRuns - MidAns)
            Loop

        End If
    Next i

    Application.ScreenUpdating = True
    MsgBox (Timer - benchmark)

End Sub


 
Old March 13th, 2008, 06:49 PM
Authorized User
 
Join Date: Nov 2007
Posts: 48
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Keith Smith,

How about:
wks.Cells(5 + i, 7) = MidGuess


Have a great day,
Stan

stanleydgromjr

Windows Vista Business and Excel 2003, 2007.
 
Old March 14th, 2008, 07:32 AM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Stan

Thanks for the reply!

No, that makes no difference. I simply get the error 'Method 'Default' of object 'Range' failed'.






Similar Threads
Thread Thread Starter Forum Replies Last Post
"Value2" property of Range object sektor Excel VBA 1 April 11th, 2008 03:28 AM
Setting property value of class - objectdatasouce ranjan74feb ASP.NET 2.0 Professional 0 October 20th, 2007 03:51 AM
DefaultValue Property Setting Failing SerranoG Access VBA 5 April 2nd, 2007 12:40 PM
Setting "DBEngine.SystemDB" property jkuusik BOOK: Access 2003 VBA Programmer's Reference 2 December 28th, 2005 06:51 AM
Error setting Formula Array property for a Range arnowitz Excel VBA 2 February 5th, 2004 02:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.