Results 1 to 2 of 2

Type Mismatch Trying to Delete Rows

Threaded View

  1. #1
    Registered User
    Join Date
    01-12-2011
    Location
    Michigan, USA
    MS-Off Ver
    2010
    Posts
    16

    Type Mismatch Trying to Delete Rows

    I have a macro that I've been using in order to clean up these text reports I receive from our ancient distribution management system. This macro has worked perfectly except for this customer, because their name has the correct amount of characters to throw a wrench into my code. The columns are separated in such a way that "- INDUS" is in its own cell, and Excel thinks this is a formula since it starts with the 'minus' symbol. This shows up as "#NAME?" in the cells where this is present (all in Column C), and gives me a type mismatch error 13 whenever I run the macro.

    I have included the code parts that may need troubleshooting below. Perhaps a formatting change would do the trick in the Text To Columns portion (I haven't yet found a working method). Note, however, that the columns must be in their current positions, or the other data will not be properly sorted. Or maybe some sort of error handling code needs to be included where the columns are deleted. Either way, I am unsure of the fix, and would greatly appreciate any help.

    Code for my text to columns:
    Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
            FieldInfo:=Array(Array(0, 1), Array(16, 1), Array(32, 1), Array(40, 1), Array(58, 1), _
            Array(70, 1), Array(82, 1), Array(96, 1), Array(97, 1), Array(103, 1), Array(108, 1)), _
            TrailingMinusNumbers:=True
    Code to Delete Rows:
    LR = Cells(Rows.Count, "A").End(xlUp).Row
        For i = LR To 1 Step -1
            If Cells(i, "E").Value = "" Or Cells(i, "C").Value = "" _
            Or Cells(i, "E").Value = "OLD PRICE" Then
                Rows(i).EntireRow.Delete
            End If
        Next i
    I have also attached a spreadsheet that illustrates the before and after on the trouble-causing row of text to columns.


    Edit: Looks like I solved my own problem (why would I not have thought to do this?), as if I just use On Error Resume Next before the code, then the macro finishes properly. I'm not quite sure if this is the ideal solution though, so if anyone has anything better please let me know. Otherwise I will consider this solved.
    Attached Files Attached Files
    Last edited by sweetnumb; 05-04-2011 at 02:53 PM. Reason: solved my own issue

Thread Information

Users Browsing this Thread

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

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