+ Reply to Thread
Results 1 to 16 of 16

Runtime error "1004"

  1. #1
    Registered User
    Join Date
    06-05-2015
    Location
    Fremont, CA
    MS-Off Ver
    2013
    Posts
    10

    Runtime error "1004"

    Hi,
    We have an Excel macro. It works for all other versions but fails with Excel 2013 with following error -

    Application defined or Object defined error.

    The error occurs at the following line -
    Please Login or Register  to view this content.
    The rRange is 8:10, 10:20, 12:10, 13:20

    Prior to setting the validation it's setting the rRange with following code -

    Dim rRange As Range

    iLastCol = Range("I6").Value
    Set rRange = Range(Cells(iRow, 10).Address + ":" + _
    Cells(iRow + 2, iLastCol).Address + "," + _
    Cells(iRow + 4, 10).Address + ":" + _
    Cells(iRow + 5, iLastCol).Address)

    This is a valid range. Also, once error is received I debugged to press F8 a few times. I then checked the validation rule in the actual spreadsheet this macro created and the rule is present in all above cells. Why this error in Excel 2013 only?
    Last edited by rsinha; 06-05-2015 at 08:21 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Runtime error "1004"

    Hello rsinha,

    Welcome to the Forum!

    From what I see there are no coding conflicts. I suggest you post a copy of the workbook for further review.

    Please redact any sensitive or confidential information before you post the workbook.

    How To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    03-26-2014
    Location
    Nowhere, somewhere
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Runtime error "1004"

    I have no idea why it only fails in 2013, but is it possible that Validation was already applied to the range?

    Try adding .Delete to the beginning of the With block.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-05-2015
    Location
    Fremont, CA
    MS-Off Ver
    2013
    Posts
    10

    Re: Runtime error "1004"

    Adding .Delete didn't work and the same error occurred on Validation.add

  5. #5
    Registered User
    Join Date
    06-05-2015
    Location
    Fremont, CA
    MS-Off Ver
    2013
    Posts
    10

    Re: Runtime error "1004"

    Hi
    I have attached two docs, SCPM-Macro_Tool_v3.3_temp.xls - this is the macro, Input Forecast Download-1record.txt - is the input file on which the macro operates. During debugging session I start F8 at openX macro/OpenMacroTool_Bucketized(). It will ask to browse a file, where I select the attached input file.
    At some point the control goes into CopyX macro/CopyInputToModify(bBucketize As Boolean). From there when it reads the 2nd line of the input file it goes to Collab Tools macro/CreateNewCollab().
    From there to SetQuantityFields(). From there to DataTools macro/UnlockCells(rRange). This is where adds the validation with following code -


    With rRange.Validation
    .Add Type:=xlValidateWholeNumber, _
    AlertStyle:=xlValidAlertStop, _
    Operator:=xlGreaterEqual, _
    Formula1:="0"
    .ErrorTitle = "Integers"
    .ErrorMessage = "Please enter a positive integer value"

    and fails at .Add Type:= line.

    Thanks for help. Hoping you will continue to This issue is driving me nuts. Thanks again.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    03-26-2014
    Location
    Nowhere, somewhere
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Runtime error "1004"

    Unfortunately, I do not have Excel 2013 to verify your issue.

    The only thing that I can think of is the fact that you are using a multi-area range and perhaps something has changed from earlier versions to prevent setting validation on such a range?

    You could try the following to see if this hypothesis is valid.

    Please Login or Register  to view this content.

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,044

    Re: Runtime error "1004"

    rsinha, it seems that you also post under the ID "punter"? (same IP 1637.114.103.51)

    http://www.excelforum.com/excel-prog...004-issue.html
    Last edited by FDibbins; 06-09-2015 at 12:11 AM.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  8. #8
    Registered User
    Join Date
    06-05-2015
    Location
    Fremont, CA
    MS-Off Ver
    2013
    Posts
    10

    Re: Runtime error "1004"

    FDibbins,
    The post - http://www.excelforum.com/excel-prog...004-issue.html, is not mine.

  9. #9
    Registered User
    Join Date
    06-05-2015
    Location
    Fremont, CA
    MS-Off Ver
    2013
    Posts
    10

    Re: Runtime error "1004"

    TnTinMN,
    I put in the code that you suggested, i.e -
    Please Login or Register  to view this content.
    Now when I run it in debug mode I do not get any error at the Validation line. So that's a good progress. But I still get the error when I execute the macro by clicking on the button.
    Is there a way I can figure out which code it is executing when clicking on the button?
    Last edited by FDibbins; 06-10-2015 at 03:36 PM.

  10. #10
    Registered User
    Join Date
    03-26-2014
    Location
    Nowhere, somewhere
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Runtime error "1004"

    Quote Originally Posted by rsinha View Post
    Now when I run it in debug mode I do not get any error at the Validation line. So that's a good progress. But I still get the error when I execute the macro by clicking on the button.
    Is there a way I can figure out which code it is executing when clicking on the button?
    Well that is strange. As I stated before, I do not have Excel 2013 so the following is just guess-work on my part.

    I know that there were some significant changes in Excel 2013 and I'm starting to wonder if those are coming into play as the code is defining rRange based on the ActiveSheet in SetQuantityFields.

    For some reference reading, see: Programming for the Single Document Interface in Excel 2013

    Let's try a test to see what Workbook/Sheet rRange is pointing to when it it is defined in SetQuantityFields and you execute the code via clicking the button.

    Please Login or Register  to view this content.
    If it is not pointing to: "[Input Forecast Download-1record.txt]Modify'!$J$8:$BD$10,$J$12:$BD$13", then we have identified the problem.
    Last edited by TnTinMN; 06-10-2015 at 04:44 PM.

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,044

    Re: Runtime error "1004"

    Quote Originally Posted by rsinha View Post
    ok, but both seem to be from teh same IP

    Also, please use code tags when posting code. See my footnote above

  12. #12
    Registered User
    Join Date
    06-05-2015
    Location
    Fremont, CA
    MS-Off Ver
    2013
    Posts
    10

    Re: Runtime error "1004"

    TnTinMN,
    I added the line - MsgBox "rRange points to: " & rRange.Address(True, True, xlA1, True). Strangely, the rRange.Address is showing the same value whether run in debug mode or by clicking the button. The value of range in both cases is -

    rRange points to: '[IBM Forecast Download-kamran-1record.txt]Modify'!$J$8:$BD$10,$J$12:$BD$13

    When clicked on the Button to run and it fails on the Validate line, thereafter I choose to go in debug mode and then it completes the entire code fine.
    I do not understand this behavior.

  13. #13
    Registered User
    Join Date
    03-26-2014
    Location
    Nowhere, somewhere
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Runtime error "1004"

    Quote Originally Posted by rsinha View Post
    I added the line - MsgBox "rRange points to: " & rRange.Address(True, True, xlA1, True). Strangely, the rRange.Address is showing the same value whether run in debug mode or by clicking the button. The value of range in both cases is -

    rRange points to: '[IBM Forecast Download-kamran-1record.txt]Modify'!$J$8:$BD$10,$J$12:$BD$13

    When clicked on the Button to run and it fails on the Validate line, thereafter I choose to go in debug mode and then it completes the entire code fine.
    Well that ruled out that possibility.

    One thing that happens when you enter debug is that control is returned to the OS and the message pump runs.

    I really hate to make this next suggestion, but there is nothing to lose at this point. Add a call to DoEvents and see what happens.

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    06-05-2015
    Location
    Fremont, CA
    MS-Off Ver
    2013
    Posts
    10

    Re: Runtime error "1004"

    When I added Application.DoEvents it gave me following error -

    'Object doesn't support this property or method"

    So I added just 'DoEvents'. Running this both in debug or via button didn't do anything.
    BTW, one difference I see when executing the code in debug mode is that following line of code -
    iLastRowIn = Cells.SpecialCells(xlLastCell).Row

    gives this error only when running in debug mode -

    "You cannot use this command on a protected sheet.
    To use this command, you must first unprotect the sheet"

    So then I go to the input spreadsheet and there first add Protect Sheet and the Unprotect sheet. Then continue with the program.
    This error doesn't occur if I run it by clicking on the button. Not sure if that has anything to do with why the Validate works in debug mode.

  15. #15
    Registered User
    Join Date
    03-26-2014
    Location
    Nowhere, somewhere
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Runtime error "1004"

    Quote Originally Posted by rsinha View Post
    When I added Application.DoEvents it gave me following error -

    'Object doesn't support this property or method"

    So I added just 'DoEvents'. Running this both in debug or via button didn't do anything.
    Oops, That should have been VBA.DoEvents

    Quote Originally Posted by rsinha View Post
    BTW, one difference I see when executing the code in debug mode is that following line of code -
    iLastRowIn = Cells.SpecialCells(xlLastCell).Row

    gives this error only when running in debug mode -
    This leads me back to my previous suspicion about the implicit use of ActiveSheet throughout this code and that perhaps the ActiveSheet (and/or WorkBook) is not what the code is assuming. The code has many Something.Select statements in it and this type of coding in error prone.

    It is better to be explicit in code and specify the WorkBook when declaring a Worksheet and to Specify a WorkSheet when declaring a Range. I saw rudiments of full range path specification in parts of the code, but it the style reverted back to using Select.

    There is not anything more that I can offer you to solve this problem. Hopefully some one that has Excel 2013 will take a look and be able to offer something.

    Good Luck.

  16. #16
    Registered User
    Join Date
    06-05-2015
    Location
    Fremont, CA
    MS-Off Ver
    2013
    Posts
    10

    Re: Runtime error "1004"

    Thank you so much for your help.

    Any Excel 2013 gurus out there ??????

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Frequently Used Macro now Giving a" Runtime Error '1004 Application-Object Defined Error"
    By rjw524 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-02-2015, 02:39 PM
  2. Issue with "Runtime error 1004: Cannot rename a sheet to the same name..."
    By joch329 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2014, 10:21 PM
  3. [SOLVED] Excel VBA Runtime error '1004' "If WorksheetFunction.Find" function
    By miguelitoven in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-11-2013, 04:34 PM
  4. Runtime Error 1004 "Active method of range class failed".
    By new2excel2012 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2012, 07:55 AM
  5. runtime error "1004", no data selected to parse
    By surgical in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-10-2010, 11:41 AM

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