2016-05-14 11 views
1

セルのテキストを基にした同じブックの別のシートのセルにリンクするハイパーリンクを作成しようとしています。現在のセル Excelマクロアクティブなセルの内容に基づいて別のシートへのハイパーリンクを作成するVBA

  • Inventory!$A$1:$A$2000です - -

    =HYPERLINK("[Five Ecom - Floor Plan.xlsx]Inventory!" & 
        ADDRESS(MATCH('8th'!F9,Inventory!$A$1:$A$2000,0),1),'8th'!F9) 
    
    • '8th'!F9セル先の範囲

    優しいテキストは次のようになります。私は、結果が手動で、ここでそれを行うことを試みました同じ現在のセルの内容。

    ここでは文字列の操作が特に難しいので、コードを複数の変数に分けることにしました。これまでは、目的の出力と結果を実行時エラー '1004'に生成できませんでした。あなたが交換した場合

    Public Sub Convert_To_Hyperlinks() 
        Dim cell As Range 
        Dim x As String 
        Dim y As String 
        Dim z As String 
        Dim c As String 
    
        For Each cell In Intersect(Selection, ActiveSheet.UsedRange) 
         If cell <> "" Then 
          c = ActiveCell.Value 
          x = "=HYPERLINK(""[Five Ecom - Floor Plan.xlsm]Inventory!"" & ADDRESS(MATCH(""" 
          y = """, Inventory!$A$1:$A$2000,0),1),""" 
          z = """)" 
          ActiveCell.FormulaR1C1 = x & c & y & c & z 
         End If 
        Next 
    End Sub 
    
  • 答えて

    1

    あなたのマクロが動作します:

    ActiveCell.FormulaR1C1 = x & c & y & c & z 
    

    で:

    ActiveCell.Formula = x & c & y & c & z 
    

    これはマッチ()は、それが探しているものは見つかっていることを前提としています。 Selection使用中のすべてのセルの

    Public Sub Convert_To_Hyperlinks() 
        Dim cell As Range 
        Dim x As String 
        Dim y As String 
        Dim z As String 
        Dim c As String 
    
        For Each cell In Intersect(Selection, ActiveSheet.UsedRange) 
         If cell <> "" Then 
          c = cell.Value 
          x = "=HYPERLINK(""[Five Ecom - Floor Plan.xlsm]Inventory!"" & ADDRESS(MATCH(""" 
          y = """, Inventory!$A$1:$A$2000,0),1),""" 
          z = """)" 
          cell.Formula = x & c & y & c & z 
         End If 
        Next 
    End Sub 
    

    (あなたは「フレンドリ名」であることを、各セルの内容を必要とすると仮定)

    +0

    これはトリックをしました!どうもありがとうございます! – rmcalingasan

    関連する問題