+ Reply to Thread
Results 1 to 6 of 6

UBound coll error after converting macro. Runtime error 13. Type mismatch.

  1. #1
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    UBound coll error after converting macro. Runtime error 13. Type mismatch.

    Hello all,

    Merry Christmas! I hope you all are safe and healthy.

    I have an existing macro which copies 4 distinct ranges from a filtered table from one worksheet to another worksheet in the same workbook. This works correctly.

    I'm now trying to convert this to be able to do that from a filtered table in one worksheet to another worksheet in another workbook.

    I think I was able to handle that first part correctly as the first copy module runs correctly and data is copied before I get the "Type mismatch" error message. But if I understand the code correctly, there's a loop at the end where I now get issues for some reason. Because of privacy issues, I'm unable to upload the actual workbook, but I can post the image of the layout with the code. This might be a shot in the dark, but I'm thinking it should be a small adjustment that someone clever in VBA can spot quickly.

    If not, my apologies and I can remove the post.

    It's this part of the code which triggers an error:

    Please Login or Register  to view this content.

    Thanks in advance.

    2.png

    Please Login or Register  to view this content.
    Last edited by Elijah; 12-29-2020 at 06:27 PM.

  2. #2
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: UBound coll error after converting macro. Runtime error 13. Type mismatch.

    A guess: the For Each rng loop may produce some ranges with only 1 cell. If rng.Cells.Count = 1, then rng.Value will not be an array. Ensure it's ALWAYS and array.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: UBound coll error after converting macro. Runtime error 13. Type mismatch.

    Hi, hrlngrv

    Thanks for the suggestion!

    I just tried implementing that code, but now I get an error here and it does not seem to run the first copy module either:

    ReDim res(1 To coll.Count, 1 To UBound(ar, 2))

  4. #4
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: UBound coll error after converting macro. Runtime error 13. Type mismatch.

    Sorry. The new error happens because of the Erase statement in the code fragment I provided.

    Would the For Each rng loop only run once? If not, ar changes on every iteration. However, since the Range collection over which iteration proceeds is

    ActiveWorkbook.ActiveSheet.ListObjects(1).DataBodyRange.Columns(R).SpecialCells(xlCellTypeVisible).Rows

    and since .Columns(R). is common to all rng references which would occur, no need to rely on ar for this. Indeed, doesn't .Columns(anything) return a single column reference? If so, wouldn't UBount(ar, 2) always be 1? Assuming not, then x.Columns(R) would itself be a multiple column Range, so would have its own .Columns property.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: UBound coll error after converting macro. Runtime error 13. Type mismatch.

    Hi, hrlngrv,

    Thank you once again!

    I just tried implementing that now and the macro runs uninterrupted. Only problem is nothing seems to be copied. But the table I copy to expanded, so something happened...

    Elijah

  6. #6
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: UBound coll error after converting macro. Runtime error 13. Type mismatch.

    Hi again,

    I'm putting this as solved. I now discovered the problem. I had some of the columns hidden using "Group". This caused issues. Ungrouping those columns took care of the problem.

    Thanks for the help, hrlngrv!

    Best regards,

    Elijah

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Type mismatch error under For x=1 To UBound(ExternalLinks)
    By bl bajracharya in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-01-2020, 06:49 AM
  2. [SOLVED] RunTime Error 13 ( type mismatch ) error is comming TextboxAfter_Update
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2017, 03:55 AM
  3. [SOLVED] Runtime error 13 type mismatch error
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-06-2016, 07:59 AM
  4. Runtime Error 13 - Type Mismatch while running Macro
    By rrajnish in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2013, 02:01 PM
  5. Runtime Error 13 -Type mismatch error
    By nikadon in forum Excel General
    Replies: 6
    Last Post: 02-25-2013, 01:37 PM
  6. Getting Type Mismatch, Runtime Error 13 With This Macro
    By HowdeeDoodee in forum Excel General
    Replies: 16
    Last Post: 11-13-2012, 07:59 AM
  7. VB error, runtime error 13 (type mismatch)
    By hindlehey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-07-2005, 08:37 PM

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