+ Reply to Thread
Results 1 to 7 of 7

VBA Program works some times and some times gives me a Run-time error '1004'?

  1. #1
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    VBA Program works some times and some times gives me a Run-time error '1004'?

    I have a simple excel spread sheet that uses VBA to add and delete a list of products. Some times it works without an error and some times it crashes with error 1004.
    It says Method 'Range' of object_'Worksheet' failed. The problem occurs when I try to call my User Form, which is invoked by a button on my workbook LagTime
    Please Login or Register  to view this content.
    Any suggestions on what I have done wrong? Thanks, redsab
    Attached Files Attached Files
    Last edited by redsab; 07-13-2014 at 10:53 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA Program works some times and some times gives me a Run-time error '1004'?

    your named range has lost the anchor cell, so its not valid.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Re: VBA Program works some times and some times gives me a Run-time error '1004'?

    nathansav, Yes I see exactly what you are talking about. I have a defined Name in my spread sheet called ProductList=OFFSET(LookupList!$A$2,0,0,COUNTA(LookupList!$A:$A)-1,1) . The reason why I could get my worksheet to run fine a few tims and then it would crash, is because I was deleting my anchor cell. My defined name then looked like this ProductList=OFFSET(LookupList!Ref#1,0,0,COUNTA(LookupList!$A:$A)-1,1). The $A$2 no longer existed in the formula, thus the error 1004. Well I did'nt bank on this problem! Now I have got to come up with a work around. My first thought was to remove the absolute reference, change $A$2 to A2; however, that did not work, I recived the same results. Maybe instead of deleting and inserting, I could delete by draging my product list up over the top of my unwanted value. And insert by moving the product list from the point of insertion down by one and insert the new product above it. I'm not sure if that wll alter my anchor point or not. Do you have a suggestion to try before a rewrite this module?
    Thanks, redsab

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA Program works some times and some times gives me a Run-time error '1004'?

    If I understand correctly your anchor is deleted by macro at some point? You could put the formula into your anchor programatically each time you delete?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  5. #5
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Re: VBA Program works some times and some times gives me a Run-time error '1004'?

    Arkadi,
    That certainly would correct my problem; however, I am not sure how to do that task. I will do some research on that and see if I can come up with code to modify the Defined Name in my spreadsheet. Thanks for the good suggestion, I will let you know what I come up with.
    redsab

  6. #6
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: VBA Program works some times and some times gives me a Run-time error '1004'?

    Hi Redsab,
    maybe so
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Re: VBA Program works some times and some times gives me a Run-time error '1004'?

    Hi nilem,

    That does delete my product number, but it also displaces the ancor cell when I delete the first item in the list and causes the same error 1004. However, I came up with the following as Arkadi suggested.
    Please Login or Register  to view this content.
    I have added this at the end of the subroutine for the Add and Delete button. Thanks for your code nilem and to everyone that helped!

    redsab

+ 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] Creating a graph with start times and end times vs time
    By khoadphamm in forum Excel General
    Replies: 14
    Last Post: 12-31-2019, 02:57 PM
  2. Replies: 8
    Last Post: 02-19-2014, 09:55 AM
  3. If a search term can be found 1 time, 2 times 3 times 4 times 5 times
    By excelcandy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2013, 09:57 PM
  4. vba program - before and after times
    By quaye28 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-13-2011, 09:02 PM
  5. Macro works in one workbook and not another - Run-Time Error 1004
    By vrobinson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2010, 07:30 PM

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