+ Reply to Thread
Results 1 to 3 of 3

Method Range of object worksheet failed

Hybrid View

  1. #1
    Registered User
    Join Date
    09-19-2012
    Location
    Asbestos
    MS-Off Ver
    Excel 2007
    Posts
    2

    Method Range of object worksheet failed

    I have a multiple sheet Excel sheet and i've included a calendar function to easily change the date of birth using this Explicit option on sheet 6
    (Codes on sheet 6)


    Option Explicit
    
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    Dim isect As Range
    If Target.Cells.Count > 1 Then Exit Sub
    
    Set isect = Intersect(Target, Range("$E$3,$E$5,$G$3:$G$5"))
    If Not isect Is Nothing Then
    frmCalendar.Show_Cal
    End If
    End Sub
    
    When I try to use the solver (with VBA code) on this sheet, i receive this error
    
    Method Range of object worksheet failed
    
    If I use the solver on any other sheets, it runs well
    
    In Module 1 the codes for the solver is
    (Button in sheet 6 calling macro in module 1)
    
    Sub OptimisingPay()
    '
    '
        SolverReset
        SolverOk SetCell:="$w$4", MaxMinVal:=3, ValueOf:="0", ByChange:="$w$3"
        SolverSolve UserFinish:=True
        SolverReset
        SolverOk SetCell:="$x$4", MaxMinVal:=3, ValueOf:="0", ByChange:="$x$3"
        SolverSolve UserFinish:=True
        SolverReset
        Range("M23").Value = Range("W3")
        Range("N23").Value = Range("X3")
        
    End Sub
    Is there a way to correct this?
    Many thanks
    Last edited by Leith Ross; 10-07-2012 at 01:34 PM. Reason: Added Code Tags

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,787

    Re: Method Range of object worksheet failed

    Not having seen your workbook I wonder if shg's comment on a solver problem could be why it does not work?

    Solver requires all the referenced cells to be on the same sheet. You can put a simple formula in a cell to reference a cell on another sheet.

    shg
    Alf

  3. #3
    Registered User
    Join Date
    09-19-2012
    Location
    Asbestos
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Method Range of object worksheet failed

    I've solved the problem by disabling the "Worksheet_SelectionChange" event by inserting these codes in the Sub that was calling for the Solver functions

    Application.EnableEvents = False
    My codes calling the solver
    Application.EnableEvents = True

    Thanks

+ 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