2

我的以下代码效果很好,但我正在尝试对其进行修改,以便与其用新索引替换索引页面的第 1 列,不如在 Cell 中开始范围C11。现在,新索引从A1索引表的单元格开始。

这是代码:

Private Sub Worksheet_Activate()
Dim wSheet As Worksheet
Dim l As Long

l = 1

    With Me
        .Columns(1).ClearContents
        .Cells(1, 1) = "INDEX"
        .Cells(1, 1).Name = "Index"
    End With

以上是我希望在单元格 C11 及以下显示的内容...

    For Each wSheet In Worksheets
    If wSheet.Name <> Me.Name Then
        l = l + 1
            With wSheet
                .Range("A1").Name = "Start_" & wSheet.Index
                .Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _
                SubAddress:="Index", TextToDisplay:="Back to Index"
            End With

            Me.Hyperlinks.Add Anchor:=Me.Cells(l, 1), Address:="", _
            SubAddress:="Start_" & wSheet.Index, TextToDisplay:=wSheet.Name
    End If
    Next wSheet

End Sub

我已经成功地修改了代码,以便每个工作表上返回索引的链接都在单元格中A4没有问题,但我不知道如何从单元格开始替换索引C11

4

2 回答 2

2

Cells(1, 1)指A1,Cells(11, 3)指C11。

于 2013-06-30T01:01:37.573 回答
0

Maybe like this ..

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim wSheet As Worksheet
Dim l As Long

    With Me
        .Columns(3).ClearContents
        .Cells(10, 3) = "INDEX"
        .Cells(10, 3).Name = "Index"
    End With
'The above is what I want to have show up in cell C11 and below...

    l = 10
    For Each wSheet In Worksheets
    If wSheet.Name <> Me.Name Then
        l = l + 1
            With wSheet
                .Range("A1").Name = "Start_" & wSheet.Index
                .Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _
                SubAddress:="Index", TextToDisplay:="Back to Index"
            End With

            Me.Hyperlinks.Add Anchor:=Me.Cells(l, 3), Address:="", _
            SubAddress:="Start_" & wSheet.Index, TextToDisplay:=wSheet.Name
    End If
    Next wSheet
End Sub
于 2013-06-30T03:42:13.950 回答