Results 1 to 2 of 2

Unable to get countif property of the worksheet function class

Threaded View

  1. #1
    Registered User
    Join Date
    04-17-2008
    Location
    Yorkshire
    Posts
    79

    Unable to get countif property of the worksheet function class

    I keep getting the following error, when I run my macro:

    Runtime error '1004'
    Unable to get countif property of the worksheetfunction class

    Sub LinkList()
        Dim SearchRange As Range
        Dim FoundCells As Range
        Dim FoundCell As Range
        Dim CompareLikeString As String
        Dim SearchOrder As XlSearchOrder
        Dim MatchCase As Boolean
        Dim OutRng As Range
        Dim Orisht As Worksheet
        Dim stringform As String
        Dim stringform2 As String
        Dim sform3 As String
        Dim rscut As String
        Dim Rsf As String
    
    
    Set Orisht = Worksheets("LinkList")
    Set OutRng = Orisht.Range("A65536")
    
        For Each Worksheet In Worksheets
            With Worksheet
            Select Case Worksheet.Name
            
            Case "LinkList"
            GoTo nxtwks
                 
            End Select
            End With
        
    'search in this range in search worksheet
        Set SearchRange = Worksheet.Range("A1:BM3000")
        CompareLikeString = "*[[]*[]]*"
        SearchOrder = xlByRows
        MatchCase = True
        
    'find matching cells
        Set FoundCells = WildCardMatchCells(SearchRange:=SearchRange, CompareLikeString:=CompareLikeString, _
            SearchOrder:=SearchOrder, MatchCase:=MatchCase)
    
        If FoundCells Is Nothing Then
            'MsgBox "No cells in this worksheet" --Not in use
        Else
            For Each FoundCell In FoundCells
                
    stringform = FoundCell.Formula
    
    
    
    'trim stringform of cell references
        For x = 1 To 6
        Rsf = Right(stringform, x)
        rscut = Left(Rsf, 1)
        If rscut <> "!" Then GoTo Nxt:
        stringform2 = (Left(stringform, Len(stringform) - (x + 1)))
    Nxt:
        Next x
    
     'time off the  = so not recorded as a formula
     sform3 = Right(stringform2, Len(stringform2) - 2)
    
    'if the link has already been listed dont record again 
    If Application.WorksheetFunction.CountIf(Worksheets("LinkList").Range("A1:A65536"), sform3) > 0 Then GoTo skip
                
            OutRng.End(xlUp).Offset(1, 0).Value = _
            sform3
                
    skip:
            Next FoundCell
        End If
        
    nxtwks:
     Next Worksheet
    
    End Sub
    The macro searches all sheets for external links, and records unique entries the linklist worksheet. (original function from an online example I cant recall where).

    It works great where there is only 1 link in a cell. However it trips up when there are for instance link+link in the cell formula. It dies at the countif line with the above error.

    Does anyone have any idea why? While I'd prefer to leave the countif line in to remove duplicate entries, there wont be too many of these types of values in the workbooks anyway, so I tried to have it just skip the 'check if already listed' part if this error occured and just add the link to the list anyway (to be sorted out manually later) but i cant seem to make an error handler that works either.

    Ideas experts?!
    Last edited by mikeyfear; 05-23-2008 at 08:39 AM.

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