excel - 将文本格式化为粗体
问题描述
此公式根据该行中包含特定值的单元格为整行着色。
For Each Cell In .Range("Y5:" & .Range("Y1500").End(xlDown).Address)
If .Cells(Cell.Row, 25).value = "Super Project" Then
Cell.EntireRow.Interior.Color = vR(WorksheetFunction.RandBetween(1, n))
End If
Next
End With
如何使“B”列中的单元格也变为粗体?
解决方案
加粗单元格:Range.Font.Bold = True
您的目标单元格位于Col Y
(Col 25) 中,因此要到达Col B
(Col 2),您需要向后退(偏移值)23 列,结果是:
Cell.Offset(0,-23).Font.Bold = True
我强迫症的一面坚持建议你
- 正确缩进
- 修改循环范围(见代码)
- 列
Y
= 列25
。不需要.Cells(Cell.Row, 25)
。只分析变量,Cell
- 最后,区分您声明
Cells
的对象和变量Cell
可能会造成混淆并导致错误。更改为类似的东西,这样区别就很明显了。Cell
MyCell
Dim MyCell as Range
With Sheets(1) 'Some Sheet
For Each MyCell In .Range("Y5:Y" & .Range("Y" & .Rows.Count).End(xlUp).Row)
If MyCell = "Super Project" Then
MyCell.EntireRow.Interior.Color = vR(WorksheetFunction.RandBetween(1, n))
MyCell.Offset(,-23).Font.Bold = True
End If
Next
End With
推荐阅读
- python - Dynamodb 扫描分页没有按我的预期工作
- r - 计算在R中存储为字符的变量
- django - 你能在 DRF ModelViewSet 中获取请求方法吗?
- sql - 选择每组前 1 名并转换
- c# - 如何检查列表中的所有项目是否为空字符串或空值,如果为真,则执行 asp.net
- pytest - 有没有办法从 pytest.ini 文件配置 pytest_plugins ?
- regex - 正则表达式所有格匹配字符串末尾的零个或一个字符
- c++ - 根据每行中所有正偶数元素的总和对二维数组的行进行升序C++
- r - 使用 R 为 cophylo 树中的颜色提示标签
- javascript - 从javascript中的嵌套列表中获取匹配的值