制作检查清单, 用户指示在单元格中输入“Ok”或“X”。 工作表列是月份,行是要检查的组件。如果用户输入“X”,我希望该单元格自动更改为超级链接,单元格仍然显示“X”超链接应该将用户带到工作簿中的Sheet2,在那里他们将输入异常信息。需要多列。 这是我的,但它不起作用。感谢您的帮助。
Sub Exceptions()
'
' Exceptions Macro
' Macro recorded 12/9/2010 by
'
'
If ThisWorkbook.Sheets("Inspection").Range("B9").Range("B100").Value = "X" Then
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
"Exceptions!A1", TextToDisplay:="X"
End If
End Sub
答案 0 :(得分:0)
如果用户在工作表1中的任何位置键入“x”或“X”,则以下代码将添加指向工作表例外范围A1的超链接:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = "x" Or Target = "X" Then
Target.Hyperlinks.Add Anchor:=Target, Address:="", SubAddress:="Exceptions!A1", TextToDisplay:=Target.Value
End If
End Sub
有几点需要注意:
Worksheet_Change
事件中更新 - 限制指向某些行/列的超链接
如果要限制特定代码区域的超链接,请使用以下代码:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rangeLimit As Range
//Set you rangeLimit accordingly. Examples shown below...
Set rangeLimit = Range("A1:A10") // Only allow hyperlinks in range A1 to A10
Set rangeLimit = Range("A1:A10,B1:B5") // Only allow hyperlinks in range A1 to A10 and B1 to B5
Set rangeLimit = Range("A:A,C:C") // Only allow hyperlinks in columns A and C
If Not Intersect(rangeLimit, Target) Is Nothing Then
If Target = "x" Or Target = "X" Then
Target.Hyperlinks.Add Anchor:=Target, Address:="", SubAddress:="Sheet2!A1", TextToDisplay:=Target.Value
End If
End If
End Sub