+ Reply to Thread
Results 1 to 5 of 5

Excel VBA deleting rows that do NOT have specific value (text) - causes Error Code 13

  1. #1
    Forum Contributor
    Join Date
    01-31-2015
    Location
    East Midlands
    MS-Off Ver
    Excel 2019
    Posts
    132

    Excel VBA deleting rows that do NOT have specific value (text) - causes Error Code 13

    Windows 10 Excel 2019

    I have the below VB code that is throwing a Run-Time code 13 mismatch error and I can not work out why.

    It appears that the line
    Please Login or Register  to view this content.
    is causing the issue.

    I have a Excel 2019 Worksheet, "Track Data", with data in Columns A - I
    This worksheet has headers in row 1.

    The data in Columns A-I is pulled by formulas using VBA from a different worksheet in the same workbook.

    For Column I, if certain conditions are met on the other sheet the formula for Column I will either the
    text, S, M or S+M, or it will return nothing. It is not possible for any other text to be entered by the formula.

    The code below looks at Column I and where it finds a cell that does NOT have the text "S" or "M" or "S+M" it is supposed to delete the whole row.

    This would then only leave rows where Column I either has "S", "M" or "M+S".

    I have also tried placing double "" like.. ""S"", ""M"" or ""M+S"" but I still get the Run-Time code 13 mismatch error


    I would have thought it should work as it is only looking for those three specific text values.

    Please Login or Register  to view this content.
    Last edited by Belinea2010; 04-23-2024 at 06:47 PM. Reason: Clarifacation

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Excel VBA deleting rows that do NOT have specific value (text) - causes Error Code 13

    To debug the issue, add this line to the code:

    Please Login or Register  to view this content.
    Run/step through the code and when it errors look in the immediate window (CTRL+G to show it if it is not already visible) to see which cell the error occurred on.
    Then go and look at the value in that cell - it very likely contains an error value such as #VALUE! or #REF!.
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Forum Contributor
    Join Date
    01-31-2015
    Location
    East Midlands
    MS-Off Ver
    Excel 2019
    Posts
    132

    Re: Excel VBA deleting rows that do NOT have specific value (text) - causes Error Code 13

    Hi Colin

    Thank you for your reply.

    As you suggested in your post I added "Debug.Print .Address(External:=True); ":"; vbTab; .Value" to my code and ran it.

    Excel highlighted .Address in your code and gave the error "Complie error: Invalid or Unqualified reference.

    thanks

  4. #4
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Excel VBA deleting rows that do NOT have specific value (text) - causes Error Code 13

    Quote Originally Posted by Belinea2010 View Post
    Hi Colin

    Thank you for your reply.

    As you suggested in your post I added "Debug.Print .Address(External:=True); ":"; vbTab; .Value" to my code and ran it.

    Excel highlighted .Address in your code and gave the error "Complie error: Invalid or Unqualified reference.

    thanks
    Hi, it needs to go inside the With block as shown in my post.

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    O365 V2408
    Posts
    15,202

    Re: Excel VBA deleting rows that do NOT have specific value (text) - causes Error Code 13

    Try this instead...
    If not, please upload a sample file...
    Please Login or Register  to view this content.
    Can also be achieved without a loop...
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

+ 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. Deleting rows with specific text
    By gauca001 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-09-2018, 04:30 PM
  2. [SOLVED] deleting rows and columns with specific text (VBA)
    By pluqk in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-25-2014, 10:11 PM
  3. Deleting rows if specific cell is blank or have specific text
    By JoaoFerreira1985 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-11-2013, 01:18 PM
  4. [SOLVED] VBA code for deleting Rows that contain specific criteria from Filtered Data
    By carlosriver24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2012, 12:23 PM
  5. Deleting Entire Rows with specific text
    By pcoper114 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-20-2011, 09:33 AM
  6. Getting #VALUE error when deleting blank rows with VBA code.
    By NBVC in forum Excel Programming / VBA / Macros
    Replies: 37
    Last Post: 07-14-2009, 11:39 AM
  7. [SOLVED] Code deleting all rows in error
    By JOUIOUI in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-10-2006, 03:45 PM

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