Type Mismatch (error 13) when use hyberlink at VBA to Cell at another sheet

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
2,681
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi Guys?
I see error 13 (type mismatch) when Use this worksheet change event at line Hyperlink? What is Problem?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long, j As Long, Lr1 As Long, Lr2 As Long, Cr1 As Long, Cr1R As Range
 Lr1 = Range("A" & Rows.Count).End(xlUp).Row - 1
 Lr2 = Range("N" & Rows.Count).End(xlUp).Row - 1
 Cr1 = Application.WorksheetFunction.Match(Range("A" & Lr1), Sheets("Sheet1").Range("A1:A" & Lr1), 0)
 Set Cr1R = Sheets("sheet1").Range("A" & Cr1)
  If Not Intersect(Target, Range("A" & Lr1)) Is Nothing Then
   If Target.Count = 1 Then
    Application.EnableEvents = False
     Range("B" & Lr1 - 1 & ":D" & Lr1 - 1).AutoFill Destination:=Range("B" & Lr1 - 1 & ":D" & Lr1)
     Sheets("sheet2").Hyperlinks.Add Anchor:=Range("A" & Lr1).Value, Address:="", SubAddress:=Cr1R, TextToDisplay:=Range("A" & Lr1).Value
        Application.EnableEvents = True
   End If
  End If
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I find Answer & Problem:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long, j As Long, Lr1 As Long, Cr1 As Long, Cr1R As String, Lr3 As Long
 Lr1 = Range("A" & Rows.Count).End(xlUp).Row - 1
 Lr3 = Sheets("Work").Range("A" & Rows.Count).End(xlUp).Row
 Cr1 = Application.WorksheetFunction.Match(Range("A" & Lr1).Value, Sheets("Work").Range("A1:A" & Lr3), 0)
 Cr1R = Range("A" & Cr1).Address
 
  If Not Intersect(Target, Range("A" & Lr1)) Is Nothing Then
   If Target.Count = 1 Then
    Application.EnableEvents = False
     Range("B" & Lr1 - 1 & ":D" & Lr1 - 1).AutoFill Destination:=Range("B" & Lr1 - 1 & ":D" & Lr1)
     Sheets("Sheet1").Hyperlinks.Add Anchor:=Range("A" & Lr1), Address:="", SubAddress:="'" & Sheets("Sheet2").Name & "'!" & Cr1R, TextToDisplay:=Range("A" & Lr1).Value
    Application.EnableEvents = True
   End If
  End If
 End Sub
Thanks Friends.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

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