我正在尝试开发一个宏来查找工作簿内所有工作表中的特定文本并将文本设置为粗体。
这是我目前的工作正常:
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
......但没有快乐。
谁能帮我吗?
谢谢,
一个
最佳答案
试一试。全面测试。
Option Explicit
Sub Style_Worksheets()
Dim TestPhrases() As String
TestPhrases = Split("Workflow Name:,Events,Event Name,Tag File", ",")
Dim ws As Worksheet
For Each ws In Worksheets
Dim CheckCell As Range
For Each CheckCell In ws.Range("A10:A16")
Dim Looper As Integer
For Looper = LBound(TestPhrases) To UBound(TestPhrases)
If InStr(CheckCell.Value, TestPhrases(Looper)) Then
CheckCell.Font.Bold = True
Exit For
End If
Next Looper
Next CheckCell
Next ws
End Sub
关于VBA宏在单元格范围内查找特定文本并将其设置为粗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47038816/