2016-08-02 56 views
0

我試圖標記有問題的單元格,並將單元格超鏈接鏈接到另一個單元格以供日後查看。這是我的代碼。並非所有代碼都可見。我稱之爲「我」和「j」。該錯誤發生在newLink = Range("AL" & i).Hyperlinks(1).Address,聲稱它「超出範圍」。我認爲這意味着它會調用一些不存在的東西,但說實話我不確定。通過超鏈接複製編錄有問題的單元格

If Range("AK" & i).Value = "On" Then 
     If Range("AL" & i).Value = 0 And Range("AM" & i).Value = 0 Then 
      Range("AL" & i, "AM" & i).Interior.ColorIndex = 6 
      'Cells("AL" & i) = H.Address' 
      ErrorCount = ErrorCount + 1 
      Dim newLink As String 
      newLink = Range("AL" & i).Hyperlinks(1).Address 
      Range("IV" & j).Hyperlinks.Add anchor:=Range("IV" & j), Address:=Range("IV" & j) 
      Range("IV" & j).Hyperlinks(1).Address = newLink 
      j = j + 1 
     End If 
+0

你試過了沒有.address? – User632716

回答

2

如果沒有連接到電池,然後Range("foo").Hyperlinks.Count將返回0,因此,你會得到一個「超出範圍」的錯誤的超鏈接。

您只需將newLink = ...語句包裝在If中,以檢查是否有超鏈接。例如。

If Range("AL" & i).Hyperlinks.Count = 1 Then 
    newLink = Range("AL" & i).Hyperlinks(1).Address 
Else 
    'what else will you do? 
End If