+ Reply to Thread
Results 1 to 9 of 9

Run-time error

  1. #1
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 365
    Posts
    291

    Run-time error

    I have a workbook with a list of names in Sheet 1, Col A.

    I also have a macro that creates and names a new sheet for every name. That is working well.

    Then I have this macro that creates a hyperlink from the name to the sheet. It also works well but pops an error message after it runs.

    Run-time error '5':
    Invalid procedure call or argument

    The debugger highlights lines 4 and 5.

    Here is the code:

    Please Login or Register  to view this content.
    This is some code I found online but I don't completely understand it.

    Thanks for all your help so far with this project.

    Len Silva

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run-time error

    If you run the code on its own, it does not error.

  3. #3
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Run-time error

    It works fine for me. Can you upload sample workbook that reproduce the error?

    Sorry, AB33 :-)
    If you are pleased with a member's answer then use the Star icon to rate it.

  4. #4
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 365
    Posts
    291

    Re: Run-time error

    Thanks,

    Here is a cut down version with the names changed. The real one is about 100 sheets and will grow to 400 by the end of the year.

    I run the macro Sheet1.AddSheet which uses the template in sheet 2 to create new sheets.

    Then I run the macro AddHyperlink to sheet 1

    I also run these macros whenever I add new names to sheet 1

    Payment Log Test.xlsm

    Len Silva

  5. #5
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Run-time error

    OK, the problem is that you have number in A10 (last cell in column A). In the example this cell contains number 8. It tries to set ws to Worksheets(c.Value) and what happens is that there is Worksheets(8), i.e. it assigns the worksheet with index 8 to ws. Your check ws Is nothing is False and it doesn't create worksheet named 8.
    After that it tries to create hyperlink to worksheet named 8 and such sheet does not exist. here comes the error. Note that if this number is not integer or is greater than max index of worksheets collection it will rise error during worksheet creation sub.
    If you are going to have subtotal in column A, change your code that creates worksheets to reflect that fact.

  6. #6
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 365
    Posts
    291

    Re: Run-time error

    Can you help me fix it? How about if I use a named range (clients) in Sheet 1? Could you rewrite the AddHyperlink macro to reflect that?
    I definitely want to keep the tables format with totals as it makes adding new names and copying down formulas easy.

    I'm reading VBA for Dummies as fast as I can but I'm not getting it yet.

    Thanks.

  7. #7
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Run-time error

    Change
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

    Change

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run-time error

    The addsheet code will tend to create errors. The error is masked by skipping the error.
    If you remove the error, the code will not move a single line as you can not set to non-existence object.

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 365
    Posts
    291

    Re: Run-time error

    Thank you all. I am going to learn this, but I'm in my seventies and it doesn't come as easy as it once did.

+ 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. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  2. Cannot Publish Excel Pivot Chart - Run Time Error
    By crisb184 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2013, 07:04 AM
  3. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  4. run-time error ;2147023179 (800706b5) time automation error interface unknown
    By karthik72 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-02-2012, 09:31 AM
  5. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 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