2011-10-21 138 views
0

我有兩列,一列自動生成(列B),另一列(列D),自動生成列的手動值很少。Excel:自動超鏈接到另一個單元格

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

我想自動超鏈接列D,當我輸入一個新的行值。 例如條目D2應該= HYPERLINK(「#B4」,B4)

現在我可以用INDEX & MATCH計算B4,但是如何自動超鏈接呢?也就是說,如果我進入D2 14,它應該自動獲得由= HYPERLINK(「#B4,B4)代替

回答

1

你必須使用一個事件過程Worksheet_Change:看到這個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 

你只需要改變你想建立

+0

感謝公式,這種方法應該工作。 –

相關問題