【发布时间】:2017-10-31 15:16:34
【问题描述】:
我正在尝试开发一个宏来在工作簿内的所有工作表中查找特定文本并将文本设置为粗体。
这是我目前的工作正常:
Sub Style_Worksheets()
Dim ws As Worksheet
For Each ws In Sheets
ws.Activate
Dim sCellVal As String
sCellVal = Range("A1").Value
sCellVal = Range("A5").Value
sCellVal = Range("A7").Value
sCellVal = Range("B7").Value
If sCellVal Like "*Workflow Name:*" Or _
sCellVal Like "Events*" Or _
sCellVal Like "Event Name*" Or _
sCellVal Like "Tag File*" Then
Range("A1").Font.Bold = True
Range("A5").Font.Bold = True
Range("A7").Font.Bold = True
Range("B7").Font.Bold = True
End If
Next ws
End Sub
现在我目前面临的问题是我有特定文本,在一个工作表中位于单元格 A16 中,但在另一个工作表中位于 A10 中。
我有 100 多个需要样式的工作表,每个工作表的特定文本位于不同的单元格中。
我希望宏在单元格 A10 和 A16 之间查找特定文本,如果找到文本,我希望它设置为粗体。
我已尝试将以下内容添加到其相关位置:
sCellVal = Range("A10:A16").Value
和:
sCellVal Like "Workflow Level Mappings*" Or _
和:
Range("A10:A16").Font.Bold = True
...但没有快乐。
谁能帮帮我?
谢谢,
一个
【问题讨论】:
-
我建议查看
Find方法,该方法将查找您指定的文本 - 如果您有几个替代文本位要查找,您似乎需要循环。