+ Reply to Thread
Results 1 to 8 of 8

Runtime Error 13

Hybrid View

DanzaNZ Runtime Error 13 10-17-2013, 06:28 PM
TMS Re: Runtime Error 13 10-17-2013, 07:57 PM
xladept Re: Runtime Error 13 10-17-2013, 08:29 PM
DanzaNZ Re: Runtime Error 13 10-17-2013, 08:45 PM
martindwilson Re: Runtime Error 13 10-17-2013, 08:52 PM
xladept Re: Runtime Error 13 10-17-2013, 09:29 PM
DanzaNZ Re: Runtime Error 13 10-17-2013, 09:53 PM
xladept Re: Runtime Error 13 10-17-2013, 10:13 PM
  1. #1
    Forum Contributor
    Join Date
    06-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    124

    Runtime Error 13

    Hi all

    I am getting Run-time Error 13 from the following code:

    -----------------------------
    Dim c As Range
     Application.ScreenUpdating = False
    For Each c In Range("A:A")
     If c.Value = "This is an estimate only and applies for the termination date displayed." Then
     c.Offset(1, 0).EntireRow.Insert
     End If
    Next c
    -----------------------------

    Can anyone help with this?
    This code is designed to insert a blank row after C.value (Specified Text).
    It works for the first few 100 rows, but then shows the Run-time error.

    Thanks in advance!
    Last edited by DanzaNZ; 10-17-2013 at 09:38 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,208

    Re: Runtime Error 13

    First guess, you probably shouldn't be trying to insert rows into an entire column. Second guess, when you want to insert or delete rows, you should start from the bottom and work up. That means you can't use For Each cell. You need to use a loop counter and decrement it from the maximum number of rows of actual data down to 1 or 2.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Runtime Error 13

    Hi Piggles,

    Change your insert code to:
    Rows(c.Row + 1).Insert
    and
    If c="" Then Exit Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Contributor
    Join Date
    06-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    124

    Re: Runtime Error 13

    Thanks for the xladept

    Maybe I am doing it wrong.....

    --------------------------
    Dim c As Range
    Application.ScreenUpdating = False
    For Each c In Range("A:A")
    If c.Value = "This is an estimate only and applies for the termination date displayed." Then
    Rows(c.Row + 1).Insert
    If c = "" Then Exit Sub
    End If
    Next c
    --------------------------

    Same Error with this one.
    Would I be on the right track to go...
         If not c.Value = "This is an estimate only and applies for the termination date displayed." Then Exit Sub
    Last edited by DanzaNZ; 10-17-2013 at 08:55 PM.

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Runtime Error 13

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Runtime Error 13

    Hi Piggles,

    I guess I can respond since you've got the code tags:

    Sub AddRows()
    Dim c As Range
    Application.ScreenUpdating = False
    For Each c In Range("A:A")
    If c.Value = "This is an estimate only and applies for the termination date displayed." Then
    Rows(c.Row + 1).Insert
    End If
    Next c
    End Sub
    Did you have the sub...end sub? The Exit Sub line I wrote is inappropriate - I was going to edit my post and delete that part - Is there any other code in your routine? Because the code worked, error free, for me. If so maybe Trevor is right!????

  7. #7
    Forum Contributor
    Join Date
    06-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    124

    Re: Runtime Error 13

    Thank you very much xladept!!!!

    The issue was a '?NAME' Error in the sheet.
    I have removed this and it works very well.

    Cheers
    Dan

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Runtime Error 13

    You're welcome

+ 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] VBA Error: Runtime Error 1004: AutoFilter method of Range class failed
    By jl22stac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-03-2013, 07:27 PM
  2. [SOLVED] Range error in code, runs alone but not inside my full program, giving runtime error 1004
    By charizzardd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2012, 03:34 PM
  3. runtime error 3265 error in a VBA Query to pull info from ERP Database
    By NBVC in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-12-2010, 03:59 PM
  4. Excel xmlHTTP object error message - system/runtime error
    By Porky2007 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-23-2007, 09:36 AM
  5. [SOLVED] Excel 2003 Macro Error - Runtime error 1004
    By Cow in forum Excel General
    Replies: 2
    Last Post: 06-07-2005, 09:05 AM

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