+ Reply to Thread
Results 1 to 8 of 8

runtime error '13' type mismatch

Hybrid View

  1. #1
    Registered User
    Join Date
    06-21-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    56

    runtime error '13' type mismatch

    Hi there!

    I'm using the following code:

    Dim rows As Integer
    rows = Sheets("sheet3").UsedRange.rows.Count
    For i = 2 To rows
        If Cells(i, 44).value = "#VALUE!" Then
            Cells(i, 44).ClearContents
        End If
    Next i
    There is a formula in the cell already, but I guess since it shows up false, it sets it as "#VALUE!"

    Any help is appreciated! THANKS!!

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,984

    Re: runtime error '13' type mismatch

    Try this:
    Dim lngrows As Long
    lngrows = Sheets("sheet3").UsedRange.rows.Count
    For i = 2 To lngrows
        If IsError(Cells(i, 44).value) Then
            Cells(i, 44).ClearContents
        End If
    Next i
    Note: I renamed your rows variable as rows is already an Excel property and I changed the data type to Long rather than integer since there are more rows in a sheet than an integer can cope with.
    Last edited by romperstomper; 08-18-2010 at 04:09 PM.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: runtime error '13' type mismatch

    Another alternative based on your assertion the cells contain formulae

    With Sheets("Sheet3")
        On Error Resume Next
        .Range(.Cells(2,44),.Cells(.UsedRange.Rows.Count,44)).SpecialCells(xlCellTypeFormulas,xlErrors).ClearContents
        On Error GoTo 0
    End With

  4. #4
    Registered User
    Join Date
    06-21-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: runtime error '13' type mismatch

    Ah it worked!

    THANKS!!

    (By the way, you had still left the "rows=sheets(sheet3)...." instead of changing it to lngrows which screwed everything up and then I saw it and changed it).

    THANKS!!!!!

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,984

    Re: runtime error '13' type mismatch

    don't know what you mean...

  6. #6
    Registered User
    Join Date
    06-21-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: runtime error '13' type mismatch

    Nevermind. It was my mistake actually.

  7. #7
    Registered User
    Join Date
    06-21-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: runtime error '13' type mismatch

    Hi.

    I have a vba macro that automates a lot of this and was wondering when taking out the #VALUE! values in the cells, it deletes the formula's too. And I tried adding this line to the vba code before it dealt with that column:

    Range("AR2").Formula = "=DATEVALUE(MID(TRIM($U2&" "&$U2),FIND("^^",SUBSTITUTE(TRIM($U2&" "&$U2)," ","^^",CHOOSE(COLUMNS($AR2:AR2),2,5)))+1,2)&MID(TRIM($U2&" "&$U2),FIND("^^",SUBSTITUTE(TRIM($U2&" "&$U2)," ","^^",CHOOSE(COLUMNS($AR2:AR2),1,4)))+1,3))"

    but it keeps giving me an error because of the " " and ^^

    Any way to fix this?

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,984

    Re: runtime error '13' type mismatch

    I was joking - I went back and edited the post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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