我是VBA的新手并编写了一个重新编号表的代码。
Sub Index()
Dim FirstRow, FirstColumn, BannerRow, FoundRow, FoundCol As Integer
Dim abc As Range
Dim x, i, col1, col2, row1, row2, y As Integer
Dim rangeTemp As Range
Dim lastrow As Long
Dim initial, p As Long
Dim ws As Worksheet
x = 2
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
initial = 1
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
FirstRow = 1
For k = 1 To lastrow
If InStr(Cells(k, 2).Value, "Table ") <> 0 Then
FirstRow = k
BannerColumn = Cells(k, Columns.Count).End(xlToLeft).Column
Cells(FirstRow, x).Value = "Table " & initial
initial = initial + 1
End If
Next k
Next
End Sub
宏将重新编号从1到最后的所有表,现在我的问题是如果我有如下输出
Table 1
Title - what is on Table
或
Table 1
Title - Are you comfort Table
我的宏文本中"Table "
的任何内容都将失败。我应该使用什么来进行比较并使其成为错误证明。请建议。
(如果可能的话,我不会寻找代码或命令只是建议,我应该考虑什么)