+ Reply to Thread
Results 1 to 6 of 6

application defined or object defined error

Hybrid View

  1. #1
    Registered User
    Join Date
    01-17-2010
    Location
    israel
    MS-Off Ver
    Excel 2007
    Posts
    3

    application defined or object defined error

    Hi,

    i have this code that i wrote in excel 2007
    its work exelent but when i am trying to run the script in excel 2003 i got an error 1004
    applocation defined or object defined error
    this code change the datavalidation list dynamicly depands on a value in a cell

    i hope that you can help me

    shay

    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Target.Address = "$C$66" Then
            If Range("CompBranch") = "áçø òðó" Or Range("CompBranch") = "" Then
                Range("CompSubBranch").Select
                Sheet1.Unprotect Password:="veryfunny!"
                With Selection.Validation
                .Delete
                .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
                :=xlBetween
                End With
                Sheet1.Protect Password:="veryfunny!"
                Range("CompSubBranch") = Empty
                Exit Sub
            End If
            Call GenerateSubBranchList
            Range("CompSubBranch") = "áçø úú òðó"
        End If
            
    End Sub
    
    Sub GenerateSubBranchList()
        Dim rng As String
        rng = GetRange(Range("H66").Value)
        Range("CompSubBranch").Select
        Sheet1.Unprotect Password:="veryfunny!"
    
        With Selection.Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
             xlBetween, Formula1:="='List'!" & rng
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With    
        Sheet1.Protect Password:="veryfunny!"    
    End Sub
    
    Function GetRange(val As Integer) As String
       Dim startPnt As Integer 
       Dim endPnt As Integer
       For Each Item In Range("'List'!Q2:Q200")
        If Item.Value = val And startPnt = Empty Then startPnt = Item.Row
        If Item.Value = (val + 1) And endPnt = Empty Or Item.Value = Empty And endPnt =Empty Then endPnt = Item.Row - 1
      Next
       GetRange = "$P" & startPnt & ":$P" & endPnt
    End Function
    Last edited by SMazoz; 01-17-2010 at 06:10 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: application defined or object defined error

    Hi and welcome to the forum.

    Which line of your code gives you the error?

    Regards
    Last edited by teylyn; 01-17-2010 at 06:25 AM. Reason: OP responded to mod request
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    01-17-2010
    Location
    israel
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: application defined or object defined error

    hi Rechard

    i dont know because i am using excel 2007 and its work fine and the person that get my excel file use
    excel 2003 .
    the only message that he get is application defined or object defined error

    shay

  4. #4
    Registered User
    Join Date
    12-27-2009
    Location
    Paris, France
    MS-Off Ver
    Excel 2003
    Posts
    64

    Re: application defined or object defined error

    Hello,

    Try to change "Sheet1" with "Me" in your code.

    Best regards.

    PMO
    Patrick Morange

  5. #5
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: application defined or object defined error

    A few things that I notice

    Range("CompSubBranch") = Empty
    Empty is used as an unitialized vaiable. Just use
    Range("CompSubBranch") = ""
    For a validation (between) I expect a Formula like
    Formula1:="1", Formula2:="3"
    I would not use this : Sheet1.Protect

    Instead
    Dim Ws1 as Worksheet
    
    Set Ws1 = Worksheets("Sheet1")
    Ws1.Protect
    why have
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
    When the strings are "" (empty) ?

    I understand that your rng goes upto Q200, but where it could go wrong:
    Function GetRange(val As Integer) As String
       Dim startPnt As Integer 
       Dim endPnt As Integer
       For Each Item In Range("'List'!Q2:Q200")
        If Item.Value = val And startPnt = Empty Then startPnt = Item.Row
        If Item.Value = (val + 1) And endPnt = Empty Or Item.Value = Empty And endPnt =Empty Then endPnt = Item.Row - 1
      Next
       GetRange = "$P" & startPnt & ":$P" & endPnt
    End Function
    Use startPnt = "" and
    An integer can take values up to 32,767.

    startPnt = Item.Row, so theoretically it can become as large as Cells.rows.Count, which is already 65,536 in XL2003.
    This will give an overflow error '6'

    Where it goes wrong (I think) is here Range("'List'!Q2:Q200")
       Set WsList = Worksheets("List")
       For Each Item In WsList.Range("Q2:Q200")
    Last edited by rwgrietveld; 01-17-2010 at 10:52 AM.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  6. #6
    Registered User
    Join Date
    01-17-2010
    Location
    israel
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: application defined or object defined error

    hi,

    still not working but when i remove the code as shown

    its OK , so something in this code is not working in excel 2003

    ' With Selection.Validation
       '    .Delete
       '    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
       '     xlBetween, Formula1:="='List'!" & rng
       '    .IgnoreBlank = True
       '    .InCellDropdown = True
       ' End With
    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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