excel - 搜索具有特定字体属性的第一个单元格的范围
问题描述
我正在搜索具有特定字体属性的第一个单元格的范围。我已经查看了类似问题的其他解决方案并遵循了他们的示例(例如Searching for Bold formatted Cells),但是 find 没有找到具有给定字体属性的单元格 - 在即时窗口中,我确认有一个单元格在具有正在搜索的 TintAndShade 和 ThemeColor 值的范围。
帮助将不胜感激。
Public Const nThemeColor = xlThemeColorAccent6
Public Const sTintAndShade = -0.249977111117893
Public Function FindFontAttributesRow(rng As Range)
'finds row number of first cell with specific font attributes in a columnar range
Dim FirstAddress As String, Cell As Range
Application.FindFormat.Clear
With Application.FindFormat.Font
.themeColor = nThemeColor
.TintAndShade = sTintAndShade
End With
Set Cell = rng.Find(What:="*", SearchFormat:=True)
If Not Cell Is Nothing Then
FindFontAttributesRow = Cell.Row
Else
MsgBox "ERROR: dbg"
Stop
End If
End Function
我已经缩小了这个问题的范围(我认为)。在下面的代码中,当 SearchFormat=True 时会出现错误 91(“Object variable or with block variable not set”),但当它=False 时不会出现,这似乎表明 FindFormat 对象没有被正确引用(但我可以不知道如何解决它!)。
Sub Macro12()
Dim cel As Range
Columns("A:A").Select
Range("A21").Activate
Application.FindFormat.Clear
With Application.FindFormat.Font
.themeColor = 10
End With
Range("A21").Activate
ThisWorkbook.ActiveSheet.Columns("A:A").Find(What:="*", SearchFormat:=True).Activate
End Sub
我相信我找到了答案:我添加了 'After' 参数(设置为 rng(1,1))并且它有效。这与 MS 文档相反,该文档说如果缺少 After arg,则默认为范围内的左上角单元格。
解决方案
我添加了 'After' 参数(设置为 rng(1,1))并且它有效。这与 MS 文档相反,该文档说如果缺少 After arg,则默认为范围内的左上角单元格。
推荐阅读
- oauth-2.0 - OAuth2 调用成功后应该做什么?
- c++ - C++ 宏表达式中的井号符号
- javascript - React js TypeError:无法读取未定义的属性“状态”
- javascript - 使用 cypress 上传 pdf 文件
- airflow - 显式跳过 DAG 时的 Slack 通知
- java - 我可以在代号 One 的 Dialog.show 中插入图像吗
- azure-devops - 如何从通用工件包中下载最新版本
- python - 在体素上添加颜色条
- android-studio - 如何在不使用 findViewById 的情况下以编程方式声明和查找布局
- python - Jupyter notebook 新行 '\n' 不解释为在文本编辑器中