+ Reply to Thread
Results 1 to 3 of 3

Error 13 - missmatch

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-10-2012
    Location
    Newcastle upon Tyne
    MS-Off Ver
    Excel 2021
    Posts
    114

    Error 13 - missmatch

    Hi,

    I use the below VBA to add columns to the right of a newly added cell...

    when clicked it pauses for a second then completes is task as it should but then throw out an error 13 at this point... "If Not rng Is Nothing And Application.CountIf(rng, "") > 0 Then rng.Delete"

    any ideas?

    Private Sub CommandButton2_Click()
        Dim rng As Range
        Dim lastrow As Long
        Dim startrow As Long
        Dim i As Long
         
        Application.ScreenUpdating = False
         
        With ActiveSheet
             
            lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
            startrow = 2
            Do
                 
                For i = startrow To lastrow
                     
                    If .Cells(i, "B").Value > .Cells(i, "C").Value Then
                         
                        .Cells(i, "E").Resize(, 10).Insert shift:=xlDown
                        .Cells(i, "B").Insert shift:=xlDown
                        startrow = i + 1
                        Exit For
                    End If
                Next i
            Loop Until i > lastrow
             
            lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
            Set rng = .Range("B2").Resize(lastrow - 1)
            On Error Resume Next
            Set rng = rng.SpecialCells(xlCellTypeBlanks)
            On Error GoTo 0
            If Not rng Is Nothing And Application.CountIf(rng, "") > 0 Then rng.Delete shift:=xlUp
        End With
         
        Application.ScreenUpdating = True
        Unload Me
    End Sub

  2. #2
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Error 13 - missmatch

    try to use:
    WorksheetFunction.CountIf(RNG, "")>0
    and replace wrong:
    Application.CountIf(rng, "") > 0
    Best Regards
    MaczaQ
    ---------------------------------------------------------------------------------------------------------------------------
    If you are satisfied with the solution(s) provided, please mark your thread as Solved
    If you are pleased with my answer consider to rate it. To thank someone who has helped you, click on the star icon below their name.
    - This way you will add him some reputation points ... thanks in advance.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Error 13 - missmatch

    You can not evaluate CountIf(rng...) when rng is nothing, so you need to separate that line
    e.g
    If Not rng is nothing then
        If WorksheetFunction.Countif(....) then

+ Reply to Thread

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