excel - 由于语法错误,Excel VBA 代码无法正常工作
问题描述
我正在使用以下代码来检查单元格是否包含单词“星期六”或“星期日”。如果是,我想在其他一些单元格中添加文本。当我执行代码时 Excel 冻结(我认为它卡在循环中?)。
Sub sbFORMAT()
'delete all shiftdata
Sheets("ploegregeling").Activate
Range("ploeginput").UnMerge
Range("ploeginput").ClearContents
Range("ploeginput").ClearComments
'color weekends blue (= add W in cell, conditional formatting adds blue color + text)
Dim dag As Integer
Dim rij As Integer
Dim rij2 As Integer
Dim rij3 As Integer
dag = 3
rij = 5
Do Until dag = 33
rij2 = rij + 2
rij3 = rij2 + 17
If Cells(dag, rij).Value = "Saturday" Or Cells(dag, rij).Value = "Sunday" Then Range("Cells(dag, rij2), Cells(dag, rij3)").Value = "W"
dag = dag + 1
Loop
End Sub
代码应添加W
到范围内的每个单元格中G7:G24,H7:H24,N7:N24
,等等。通过W
在单元格中写入,它将变成蓝色(条件格式)。这是通过手动进行的。
解决方案
推荐阅读
- angular - 单元测试用例以茉莉角覆盖 router.navigate.then
- node.js - 未能查找视图
- java - Thread.sleep 没有被 PowerMockito 嘲笑
- python - 如何计算数据框中连续的最大数量?
- javascript - 当用户单击 MVC5 中的浏览器后退按钮时,在检索数据时面临问题
- debugging - 在 Xcode 12 中调试和运行 PO 命令时抛出错误
- css - 在 React Native 中使用高度设置背景颜色
- json - 将 JSON 数据展平为单个列
- javascript - 使用用户界面更新 mySQL 表 - PHP
- css - 在一行中显示修复 4 flex 框