gpt4 book ai didi

excel - 条件格式宏给了我运行时错误 1004 错误

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

打开一个 Excel 工作表
输入 橙色 进入 A1 细胞
输入 香蕉 进入 A2 细胞
输入 15 进入 B1 细胞
输入 23 进入 B2 细胞
转至 开发者 选项卡,然后单击 录制宏按钮
点击好的为了录制宏。
选择 A1 和 A2 细胞在一起
转至 首页 标签 > 条件格式 > 新规则 > 使用公式确定要格式化的单元格
输入 =B1>12
点击格式按钮
点击号码 标签
点击定制 按钮
输入 ""@
点击好的按钮
点击好的再次按钮
转至 开发者 选项卡,然后单击 停止录音按钮
新闻 Alt+F11 为了看到下面的宏。

Sub Macro1()
Range("A1:A2").Select
Selection.NumberFormat = """""@"
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=B1>12"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
ExecuteExcel4Macro "(2,1,""""""@"")"
Selection.FormatConditions(1).StopIfTrue = False
End Sub
当您运行录制的宏时,您将看到错误( 运行时错误 1004 )。
你知道怎么解决 运行时错误 1004 ?

最佳答案

我做了一些研究,找到了您的解决方案 here宏记录器正在恢复到旧的 ExecuteExcel4Macro 命令,以便为条件格式规则设置数字格式。这不是必需的。
您的代码应如下所示:

Sub Macro1()

With ActiveSheet.Range("A1:A2")
.FormatConditions.Delete 'Removes all the rules from the selection first
.FormatConditions.Add Type:=xlExpression, Formula1:="=B1>12"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).NumberFormat = """""@"
.FormatConditions(1).StopIfTrue = False
End With
End Sub

关于excel - 条件格式宏给了我运行时错误 1004 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66018679/

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