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

VL00kup

New Member
Joined
Nov 13, 2017
Messages
9
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!!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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.
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,927
Members
448,533
Latest member
thietbibeboiwasaco

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top