+ Reply to Thread
Results 1 to 23 of 23

Runtime error 13 - Type Mismatch when DIM Range as String

  1. #1
    Registered User
    Join Date
    06-18-2022
    Location
    Aberdeen, Scotland
    MS-Off Ver
    365
    Posts
    8

    Question Runtime error 13 - Type Mismatch when DIM Range as String

    I have a small macro running which puts a list of names in random order, then splits the list into two separate lists based on the total number of names in the list.
    In the macro, I set up start and end of the range as two strings 'srange' &' erange'. The start and end cells references are held in cells B79 & B80 respectively. These cell refs change depending on total number of names.

    Everything works fine in Microsoft 365, but I get a Runtime Error 13 - Type Mismatch at the first line in the code below, when I run the macro in Excel 2013.

    Any ideas what I could be doing wrong? I've already had to change my code for 2013 because it gave a 1004 error when I used INDIRECT to pick up the cell references from B79/B80.

    Any help appreciated.

    Dim sRange As String, eRange As String
    sRange = ActiveSheet.Range("B79"):
    eRange = ActiveSheet.Range("B80")
    Range(sRange & ":" & eRange).Select
    Selection.Copy
    Range("H2").Select
    ActiveSheet.Paste

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Hi there,

    Knee-jerk suggestion - without access to your workbook, anything else is very difficult:

    Please Login or Register  to view this content.

    Regards,

    Greg M

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,598

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    "... The start and end cells references .." is not enough information. We don't know what exactly is in those cells, e.g. addresses like M10, M200 or ...? When I put those addresses in the cells, the code does not crash.
    Ben Van Johnson

  4. #4
    Registered User
    Join Date
    06-18-2022
    Location
    Aberdeen, Scotland
    MS-Off Ver
    365
    Posts
    8

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Hi Greg,

    I'm new to VBA so this is going to sound like a really stupid question. Do I just type .value as shown in your reply, or is excel looking for an actual value? Do I also still need the : between the range statements?
    B79 & B80 contain cell references to another part of the same sheet, i.e. G3 & G27, but they change constantly depending on total number of names on the list.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,364

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Can't see anything in that code that would fail in any version of Excel. Rather depends on what is in cells B79 and B80. If they don't look like cell references that would fail.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,364

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Post the workbook and code. I'm sure we can improve on it for you.

  7. #7
    Registered User
    Join Date
    06-18-2022
    Location
    Aberdeen, Scotland
    MS-Off Ver
    365
    Posts
    8

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    There's actually a formula in B79 & B80 to build the cells reference I need. Formula is =CONCAT("G", B77+2). At the moment this gives the cell reference G33. Wondering if I just need to copy B79/B80 so that the formula is only picking up text?

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,364

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Shouldn't matter. See post #6.

  9. #9
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Hi again,


    Do I just type .value as shown in your reply, or is excel looking for an actual value?

    Yes, just add ".Value" (without quotes) as per my first post.



    Do I also still need the : between the range statements?

    The ":" character is used to separate statements which are on the same LINE of code, so it's not necessary to use a ":" separator if nothing else follows it on the same line.


    As mentioned in other posts, I think you're more likely to get a helpful suggestion if you post your workbook here. It often happens that the cause of a problem reveals itself only after someone has had a chance to "play around" with a workbook.


    Regards,

    Greg M

  10. #10
    Registered User
    Join Date
    06-18-2022
    Location
    Aberdeen, Scotland
    MS-Off Ver
    365
    Posts
    8

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Code attached.

    There's one macro which runs when the DRAW button is pressed. The idea behind the sheet is to do a random draw of entrants and calculate out how many Ties & Byes there will be in a knockout tournament.

    As I said previously, it works fine in Microsoft 365, but gives the Runtime error 13 - Type Mismatch in Excel 2013. Baffled??

    Thanks for your help and patience with this.

    Dave
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    And the password is???????????????
    Experience trumps academics every day of the week and twice on Sunday.

  12. #12
    Registered User
    Join Date
    06-18-2022
    Location
    Aberdeen, Scotland
    MS-Off Ver
    365
    Posts
    8

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    My apologies. I thought I had removed all passwords. It's DB14

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,364

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Your code runs for me out of the box. I'm using Excel 365.

  14. #14
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Would this do the same? Try on a copy of your original.
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    06-18-2022
    Location
    Aberdeen, Scotland
    MS-Off Ver
    365
    Posts
    8

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    That's the issue. It runs great on 365, but I get the Runtime Error 13 when I run it in Excel 2013.
    Unfortunately most of the users have older versions of Excel on their computers.

  16. #16
    Registered User
    Join Date
    06-18-2022
    Location
    Aberdeen, Scotland
    MS-Off Ver
    365
    Posts
    8

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Sorry, this doesn't work. It gives a 1004 error - This action won't work on multiple sections at the Range("G2, B78").Copy Range("I2") line.

  17. #17
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Sorry, my bad.
    That line should not be there. Just delete that line.

  18. #18
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Hi again,

    Just for information:

    When I open your posted workbook using Office 2016, I see errors caused by using the "_xlfn.CONCAT" function in Cells B78 and B79. Changing this to "CONCATENATE" removes those errors, but (strangely!) "_xlfn.CONCAT" does NOT seem to cause an error when used in (e.g) Cell B71.

    The next error occurs in Cell B73 where the "_xlfn.IFS" function is used. Replacing this function with a numeric value (88) removes the error and allows your code to run.

    I've no idea why the above should be the case - I'm just passing it on to you for information.

    Regards,

    Greg M


    P. S. There's nothing appropriate/correct about the value 88 - it's just a numeric value which allows your code to run without generating an error message.
    Last edited by Greg M; 06-19-2022 at 07:54 PM. Reason: P. S. added

  19. #19
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,598

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    1) B69: =COUNTA(B2:B65) --> can never be more than 64
    2) B73: IFS(DRAW!B69>64,"TOO HIGH", ... ---> a string
    2a) ...IFS(DRAW!B69>64,"TOO HIGH",DRAW!B69>32,"64" --> "64" in quotes is a word (i.e., sixty four),
    In B76 & 77 you are performing arithmetic operations on "words" (sixty four/2), but Excel is letting you get away with it...

    Also notice that if B69 were somehow able to be >64, then B76 would be ="too high"/2 ... and Your vba code line:
    sRange = ActiveSheet.Range("B79").Value
    would initialize sRange to "too high",
    etc.

  20. #20
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    The CONCAT function doesn't exist in 2013, which means the cells have errors in them, which is why you get a type mismatch.

    Edit: NVM, didn't read Greg's post before posting.
    Rory

  21. #21
    Registered User
    Join Date
    06-18-2022
    Location
    Aberdeen, Scotland
    MS-Off Ver
    365
    Posts
    8

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Thanks to everybody who responded to my post. Turns out there was a lot more wrong than I had anticipated, but with your help the program is now running beautifully in all versions of Excel. The main takeaway is I should have checked that the formulae and commands I was using actually existed in Excel 2010/2013, not just in 365. Lesson learned! Thanks again.

  22. #22
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,364

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  23. #23
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Runtime error 13 - Type Mismatch when DIM Range as String

    Hi again,

    Many thanks for your feedback and also for the Reputation increase - much appreciated!

    Best regards,

    Greg M

+ 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. [SOLVED] Getting Runtime Error 13 - Type Mismatch
    By mlski4751 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-07-2021, 01:10 PM
  2. Runtime Error 13 Type Mismatch
    By peakoverload in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-16-2018, 10:34 AM
  3. Runtime Error 13 (Type Mismatch) on Mac but not Windows - Range Name Problem??
    By Merf in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 06-09-2017, 04:35 PM
  4. Runtime error 13 - type mismatch
    By Polluz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2014, 11:30 PM
  5. Runtime error'13' - type mismatch
    By Polluz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-24-2014, 01:12 PM
  6. RunTime Error 13: Type MIsmatch
    By tariq2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-24-2013, 10:47 AM
  7. [SOLVED] runtime error 13 type mismatch
    By Justair07 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-28-2013, 02:46 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