Excel VBA 如果该条件发生错误,则运行下一条件
Worksheets(3).Name=Worksheets(3).Cells(1,9).Value&"(4)"OnErrorResumeNextWorksheets(3)...
Worksheets(3).Name = Worksheets(3).Cells(1, 9).Value & "(4)"
On Error Resume Next
Worksheets(3).Name = Worksheets(3).Cells(1, 9).Value & "(3)"
On Error Resume Next
Worksheets(3).Name = Worksheets(3).Cells(1, 9).Value & "(2)"
On Error Resume Next
Worksheets(3).Name = Worksheets(3).Cells(1, 9).Value
类似于上面这种方式,用if的方式去写 展开
On Error Resume Next
Worksheets(3).Name = Worksheets(3).Cells(1, 9).Value & "(3)"
On Error Resume Next
Worksheets(3).Name = Worksheets(3).Cells(1, 9).Value & "(2)"
On Error Resume Next
Worksheets(3).Name = Worksheets(3).Cells(1, 9).Value
类似于上面这种方式,用if的方式去写 展开
2个回答
展开全部
如果CELLS(1,9)里面有非法字符,你这些语句全部都要失败。如果是为了解决重名,可以先检测是否有这样名字的表,使用下面的自定义函数检查:
Function SheetExists(nm) as Boolean
Dim st as WorkSheet
set st=nothing
on error resume next
set st=sheets(nm)
on error goto 0
SheetExists = not st is nothing
End Function
主程序可以使用while一直循环,例如:
Dim i, nm
i=0
do
nm = Worksheets(3).Cells(1, 9).Value
if i>0 then nm = nm & "("& i &")"
i=i+1
loop until not SheetExists(nm)
Worksheets(3).Name = nm
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询