Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Inconsistent Runtime 13 Error (Type Mismatch) - Tearing my Hair Out

  1. #1
    New Member
    Join Date
    Nov 2017
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Inconsistent Runtime 13 Error (Type Mismatch) - Tearing my Hair Out

    Hello,

    I am hoping someone can help with a repetitive error I am getting with the VBA code below. Basically, I am looping through a series of cells and assigning a hyperlink. What is frustrating is that the same code was working for me in an older version of the file, and when I clear everything out again, seems to work again before breaking.

    The error I am getting is a Runtime 13 Error (Type Mismatch) that starts in the first ".hyperlink" bit of code. I am new to VBA, so I may be making a basic error, but I'm completely stuck.

    Code:
    Sub Race_1()Dim i As Integer
    Dim j As Integer
    Dim r As Integer
    
    
    i = 0
    c = 0
    j = 22
    r = 1
    
    
    
    
        Do Until c = 14
        
            Do Until i = 10
                
                With Worksheets("Race_" & r)
                
                .Hyperlinks.Add Anchor:=.Cells(j, 7), _
                   Address:=Worksheets("RACE_" & r).Cells(j, 49).Value, _
                   ScreenTip:="Click to View Replay", _
                    TextToDisplay:="Replay"
                    Cells(j, 7).Font.Bold = "True"
                  End With
                
                i = i + 1
                j = j + 2
                
            Loop
    
    
    
    
          i = 0
          j = j + 12
          c = c + 1
    
    
        Loop
    
    
    End Sub
    Bonus points: I would like to add another loop that will change the race # (variable "r"), and repeat the code on 10 different sheets in sequential order ("Race_1"...."Race_10")

    Thank you!!

  2. #2
    Board Regular
    Join Date
    Sep 2013
    Location
    Blue Mountains, Australia
    Posts
    3,324
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Inconsistent Runtime 13 Error (Type Mismatch) - Tearing my Hair Out

    When you get the error, have a look at the value of:

    Worksheets("RACE_" & r).Cells(j, 49)

    I think you'll find there's an error value in this cell, e.g. perhaps #N/A?

    You could rewrite your loops more efficiently using For .. Next Statements. Note you have the option to specify a Step other than the default 1. I think then you'll be able to can score your bonus points yourself?

    Also, a minor code correction:

    .Cells(j, 7).Font.Bold = True

    i.e. so that Cells refers to Worksheets("Race_" & r), and not by default to the ActiveSheet.

  3. #3
    New Member
    Join Date
    Nov 2017
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Inconsistent Runtime 13 Error (Type Mismatch) - Tearing my Hair Out

    THANK YOU! IT ALL WORKS! (including the Bonus!)

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •