Excel:自动链接到另一个Cell

时间:2011-10-21 06:25:34

标签: excel excel-formula

我有两列,一列自动生成(B列),另一列(D列),自动生成列中的手动值很少。

B           D
--------------------
1  Col1    Col2
2  12       14
3  13       16 
4  14
5  15
6  16
--------------------

当我在其中输入新的行值时,我想自动超链接列D. 例如条目D2应为= HYPERLINK(“#B4”,B4)

现在我可以使用INDEX&匹配,但我如何自动超链接呢?也就是说,如果我在D2中输入14,它应该自动被替换为= HYPERLINK(“#B4,B4)。

1 个答案:

答案 0 :(得分:1)

您必须使用事件程序工作表_更改:请参阅此article on ozgridthis one on Chip Pearson's website

类似的东西:

Private Sub Worksheet_Change(ByVal Target As Range)
   'Do nothing if more than one cell is changed or content deleted
   If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
   'Trigger the procedure only for the column D
   If Not Intersect(Target, Range("D:D")) Is Nothing Then
     'Turn off ALL events so the Target change does not trigger another time this sub
      Application.EnableEvents = False
      'Change the formula for what you ever want
       Target.Formula = "=HYPERLINK(""#B4"", B4)"
      'Turn events back on
      Application.EnableEvents = True
   End If
End Sub

您只需要更改要构建的公式。