超链接-给出运行时错误5“无效的过程调用或参数”

时间:2019-01-19 00:45:48

标签: excel vba hyperlink runtime-error

如果仅与“ sheet2”行“ b”上的值匹配,但我却出现“无效的过程调用或参数”错误,我将尝试为工作表“表”中的范围创建超链接。我一直在寻找解决方案的在线资源,但找不到任何东西。有人可以在以下代码上为我提供帮助吗?

  Sub Macro1()
  For i = 4 To 23
  If Cells(i, "A").Value <> "" Then
  k = Sheets("TABLES").Cells(i, "a").Value
  c = Application.Match(k, Sheets("Sheet2").Range("B11:B500000"), 0)
  If IsError(c) Then
  Else
  Sheets("tables").Hyperlinks.Add Anchor:=Sheets("tables").Cells(i, "A"), _
                          Address:="", _
                          SubAddress:="sheet2!F" & c, _
                          TextToDisplay:=k
  End If
  End If
  Next i
  End Sub

2 个答案:

答案 0 :(得分:0)

更改If Cells(i, "A").Value <> "" ThenIf Sheets("TABLES").Cells(i, "a").Value <> "" Then〜 希望它能工作。它不能识别第一行中的对象。

答案 1 :(得分:0)

超链接梦m

Option Explicit

Sub Error5()

    Dim i As Long
    Dim k As Long
    Dim c As Variant

    With Sheets("Tables")
        For i = 4 To 23
            If .Cells(i, "A").Value <> "" Then
                k = .Cells(i, "A").Value
                c = Application.Match(k, Sheets("Sheet2") _
                        .Range("B11:B50000"), 0)
                If IsError(c) Then
                  Else
                    .Hyperlinks.Add _
                            Anchor:=.Cells(i, "A"), _
                            Address:="", _
                            SubAddress:="Sheet2!F" & c, _
                            TextToDisplay:=CStr(k)
                End If
            End If
        Next
    End With

End Sub