【问题标题】:create a sheet with cell value automatically and hyperlinked the cell value to it自动创建一个带有单元格值的工作表并将单元格值超链接到它
【发布时间】:2014-04-18 10:13:36
【问题描述】:

我正在使用此 VBA 代码为每个单元格值创建新工作表

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim wsNew As Worksheet
    If Target.Cells.Count > 1 Then Exit Sub

        On Error Resume Next
        If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
            Set wsNew = Sheets(Target.Text)
            If wsNew Is Nothing Then Sheets.Add().Name = Target.Text
        End If
End Sub

它工作正常,但工作表是在我想要它们之后的主工作表之前创建的,我想将这些单元格值作为超链接链接到它们各自的工作表。

谢谢

【问题讨论】:

    标签: vba excel


    【解决方案1】:
    Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Cells.Count > 1 Then Exit Sub
      If Len(Target.Value) = 0 Then Exit Sub
    
      If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
        Dim wsNew As Worksheet
    
        On Error Resume Next
        Set wsNew = Worksheets(Target.Text)
        On Error GoTo 0
    
        If wsNew Is Nothing Then
          With Worksheets.Add(after:=Me)
            .Name = Target.Text
    
            Target.Hyperlinks.Delete
            Target.Hyperlinks.Add Target, "", "'" & .Name & "'!" & .Range("A1").Address(False, False, xlA1)
          End With
    
          Me.Activate
        End If
      End If
    End Sub
    

    【讨论】:

    • 感谢 GSerg。我还可以在每张纸的第一个单元格上放一个指向主纸的链接吗
    猜你喜欢
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 2023-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多