Results 1 to 4 of 4

Can't find type mismatch

Threaded View

  1. #1
    Registered User
    Join Date
    05-21-2013
    Location
    Cape Town
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    9

    Can't find type mismatch

    I am trying to run the following code but I keep getting the error "Run-time error 91: Object variable or With block variable not set"

        numberOfRows = Application.CountA(Range("A:A"))
        
        Application.CutCopyMode = False
        
        Dim numberOfRemainingDuplicates As Integer
        Dim lastOne As Variant
        Dim workingRange As Variant
    
        numberOfRemainingDuplicates = numberOfRows - 1
        lastOne = "A1"
        workingRange = "AF3:AF" & numberOfRows
        
        Do
            Range(workingRange).Select
            Selection.Find(What:="1", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
            xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
            , SearchFormat:=False).Activate
            lastOne = ActiveCell.Address
            ActiveCell.EntireRow.Select
            Selection.Insert Shift:=xlDown
            
            numberOfRows = numberOfRows + 1
            Range(lastOne).Select
            Selection.Offset(2, 0).Select
            workingRange = ActiveCell.Address & ":$AF$" & numberOfRows
            numberOfRemainingDuplicates = Application.CountA(Range(workingRange))
            
        Loop While numberOfRemainingDuplicates > 1
    (I highlighted in brown the portion of the code that gets highlighted when I enter debugging mode)

    I have tried to introduce workingRange as
    Dim workingRange As Range
    and then removing the Range functions from workingRange in the rest of the code, but then I get other errors. What confuses me the most is that before I saved and closed the workbook that contains this macro, I ran the macro once successfully, so I find it strange that this error would only appear now?

    I hope someone can see what is wrong with this code?
    Last edited by captive; 07-30-2013 at 10:51 AM. Reason: Gramatical error corrected

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Iterate Through Names, list unused: Type Mismatch with Cells.Find
    By tlafferty in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2012, 04:03 PM
  2. Range and Find function error: Type Mismatch
    By VBNewb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2011, 02:10 PM
  3. Run time error 13 Type Mismatch pointing to Find MatchCase=false
    By NukedWhale in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2009, 11:53 PM
  4. Type Mismatch Error on Find Closest Match
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2007, 11:07 AM
  5. Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 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