gpt4 book ai didi

vba - 不寻常的循环宏行为

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

我有以下代码在我的工作簿中的所有工作表上执行宏,但 excludesheets 字符串中的工作表除外。

奇怪的是,它也忽略了其他工作表,背后没有逻辑。

主页、概述和设置在最前面,然后我有 18 张要执行的工作表,然后是原始、指标、旧概述和最终排除的团队。

所有的弦乐表都被跳过了,但我想要的 9 张也被跳过了。

任何人都可以帮忙吗?

Sub Error_Check()

Const excludeSheets As String = "Home Page,Overview,Setup,Original,Metrics,Overview old,Teams"

Dim ws As Worksheet

For Each ws In Sheets
ws.Activate

If IsError(Application.Match(ws.Name, Split(excludeSheets, ","))) Then

'Macro bit

End If


Next ws

End Sub

最佳答案

我认为你的 Match语句需要有 match_type指定的参数,因为您将其留空。
试试这个(注意 0):

If IsError(Application.Match(ws.Name, Split(excludeSheets, ","),0)) Then
例如,此参数指定精确值是否匹配或最大。从 MS 文档中查看:

If match_type is 1, MATCH finds the largest value that is less than or equal to lookup_value.

If match_type is 0, MATCH finds the first value that is exactly equal to lookup_value. Lookup_array can be in any order.

If match_type is -1, MATCH finds the smallest value that is greater than or equal to lookup_value.

If match_type is omitted, it is assumed to be 1.

关于vba - 不寻常的循环宏行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25786095/

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