A P*_*A P 1 excel vba excel-vba
我正在尝试开发一个宏来查找工作簿中所有工作表中的特定文本,并将文本设置为粗体样式.
这是我目前的工作正常:
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
Run Code Online (Sandbox Code Playgroud)
现在我遇到的问题是我有一个特定的文本,在一个工作表中是在单元格A16,但在另一个工作表是在A10.
我有超过100个需要样式的工作表,并且每个工作表的特定文本位于不同的单元格中.
我希望Macro能够在单元格A10和A16之间找到特定文本,如果找到文本,我希望它将其设置为粗体样式.
我尝试将以下内容添加到相关位置:
sCellVal = Range("A10:A16").Value
Run Code Online (Sandbox Code Playgroud)
和:
sCellVal Like "Workflow Level Mappings*" Or _
Run Code Online (Sandbox Code Playgroud)
和:
Range("A10:A16").Font.Bold = True
Run Code Online (Sandbox Code Playgroud)
......但没有快乐.
谁能帮我吗?
谢谢,
一个
试一试.经过全面测试
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2039 次 |
| 最近记录: |