2015-04-03 32 views
2

我有以下代碼放入我的工作簿中的索引工作表中。它爲我的「索引」選項卡上的每個工作表創建一個超鏈接,並應在單元格「A1」中創建一個名爲「返回索引」的超鏈接。它工作得很好,但是如果我添加一個新的工作表,我必須通過選項卡並刪除第一行,我已經研究了這個問題,並沒有能夠提出任何問題來解決問題。如何刪除特定的行,當它等於某個文本?

總之,我想刪除每個工作表上包含單元格「A1」中的文本「返回索引」的第1行。有人會對此有任何建議嗎?非常感謝任何能夠就此問題提供建議的人。

Sub TCIndex() 
Dim wSheet As Worksheet 
Dim l As Long 
Dim lastRow As Long 


l = 1 

With Me 
    .Columns(1).ClearContents 
    .Cells(1, 1) = "INDEX" 
    .Cells(1, 1).Name = "Index" 
    .Rows(1).HorizontalAlignment = xlCenter 
    .Rows(1).Font.Size = 14 
    .Rows(1).RowHeight = 18 
    .Columns(1).ColumnWidth = 60 
    .Range("A1").Interior.Color = RGB(0, 0, 0) 
    .Range("A1").Font.Color = RGB(255, 255, 255) 
    .Range("A1").Font.Bold = True 
    .Range("A1:A1").Borders.LineStyle = xlContinuous 
    .Range("A2:A70").RowHeight = 15 
    .Range("A2:A70").VerticalAlignment = xlCenter 
End With 

lastRow = Range("A1").End(xlDown).Row 

For Each Cell In Range("A2:A" & lastRow) 
    If Cell.Row Mod 2 = 1 Then 
     Cell.Interior.Color = RGB(200, 200, 200) 
    Else 
     Cell.Interior.ColorIndex = xlNone 
    End If 
Next Cell 


For Each wSheet In Worksheets 
    If wSheet.Name <> Me.Name Then 
     l = l + 1 
     With wSheet 
      .Range("A1").Name = "Start_" & wSheet.Index 
      .Range("A1").EntireRow.Insert 
      .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 
+1

您需要顯示您嘗試的代碼以及它失敗的位置。 – mrbungle 2015-04-03 14:49:51

回答

1

要回答你的問題
我要刪除第1行包含文本「回到指數」,在單元格「A1」每個工作表上。

for each wrkSht in worksheets 
    if wrkSht.[A1] = "Back to Index" then 
     wrkSht.rows(1).delete 
    endif 
next wrkSht 
相關問題