Excel工作表索引

时间:2013-06-29 22:19:47

标签: excel vba indexing worksheet

我有以下代码,但我正在尝试修改它,以便不是用新索引替换索引页面的第1列,而是在单元格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中没有问题,但我无法弄清楚如何从Cell {{ 1}}

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

也许是这样..

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