gpt4 book ai didi

excel - 在除 Sheet1 和 Sheet2 之外的每个工作表上运行宏

转载 作者:行者123 更新时间:2023-12-04 21:12:28 25 4
gpt4 key购买 nike

我想在除了 sheet1 和 sheet2 之外的每张工作表上运行一个宏。

    dim rs as worksheet  
for each rs in sheets
if rs.name = "Sheet1" or "Sheet2" then
next rs
else rs.name =rs.range("
我得到错误

next without for


如何使用下一个 for 循环和 if 语句?
Dim rs As Worksheet

For Each rs In Sheets
If rs.Name = "sheet1" Or "sheet2" Then
Next ws
Else: rs.Name = rs.Range("N2") 'rename sheet base on vendor name field

End If
Next rs

最佳答案

小混混,试试:

Dim rs As Worksheet

For Each rs In ThisWorkbook.Worksheets
If rs.Name <> "Sheet1" And rs.Name <> "Sheet2" Then
rs.Name = rs.Range("N2").Value 'rename sheet base on vendor name field
End If
Next rs

End Sub

关于excel - 在除 Sheet1 和 Sheet2 之外的每个工作表上运行宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38720062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com