excel - 使用 VBA 的条件格式 - 代码不起作用
问题描述
我已经编写了以下 VBA 代码来为我的表格重新绘制边框。我还编写了小测试代码,根据 B84 的值在单元格 B11 和 B12 上应用条件格式。如果 B84=1 的值,那么我想在 B11 和 B12 中填充黄色。但它不起作用。
如果这可行,我想编写更多条件,例如,如果 C84=1,则 C11 和 C12 将填充黄色,以此类推,如果 R84=1,则 R11 和 R12 将填充黄色。
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
ReInstateBorders Range("A7:R16,A18:R23")
Application.ScreenUpdating = True
End Sub
Sub ReInstateBorders(theRange)
For Each are In theRange.Areas
For rw = 1 To are.Rows.Count - 1 Step 2
For colm = 1 To are.Columns.Count
are.Cells(rw, colm).Resize(2).BorderAround xlContinuous
Next colm
Next rw
Next are
If Sheets("timetable").Range("B84").Value = 1 Then
Sheets("timetable").Range("B11").Interior.Color = vbYellow
Sheets("timetable").Range("B12").Interior.Color = vbYellow
End If
End Sub
解决方案
推荐阅读
- android - 如何检查房间数据库是否有实体?
- java - 元素也是类中的路径名
- python - Python for 循环总是使用 else 语句
- simulink - 是否可以在 simulink 中训练分类器模型?
- ios - 添加到 viewDidLayoutSubviews 时,按钮渐变不起作用
- javascript - React useState 钩子返回旧状态值,尽管它被更新
- python - Search slice of pandas columns for value occurrence, get indices/mask of occurrences, then use that to index into a second slice of columns
- javascript - 如何同步getjson函数
- javascript - 使用 webview 在 android 中下载不同格式的 facebook 视频
- javascript - 链接事件侦听器返回子元素