简体   繁体   English

加粗一个范围内的特定文本(分成多个单元格)

[英]Bold a specific text within a range (broken up into multiple cells)

I am building a template in Excel and I would like the phrase "6. Description Summary:" to be bold using VBA.我正在 Excel 中构建模板,我希望使用 VBA 将短语“6. 描述摘要:”设为粗体。 The cell the phrase is located is not static so the code should be able to pick up the phrase anywhere within the range.短语所在的单元格不是 static 因此代码应该能够在该范围内的任何位置拾取短语。

Currently the code makes the whole range A1:G100 bold目前代码使整个范围 A1:G100 加粗

Here is what I have tried:这是我尝试过的:

 Set BoldRange = Range("A1:G100").Find("6. Description Summary:")
        If Not (BoldRange Is Nothing) Then
            BoldRange.Font.Bold = True
        End If

Would appreciate it if you could let me know if there is a way to edit this code to make it bold only the specified text.如果您能告诉我是否有办法编辑此代码以使其仅对指定的文本加粗,将不胜感激。

Update: The text is broken up into multiple cells so I am actually looking to only bold the specified string.更新:文本被分成多个单元格,所以我实际上只希望将指定的字符串加粗。

The code does what you want, I checked it myself.代码做你想要的,我自己检查过。 Set BoldRange = Range("A1:G100").Find("6. Description Summary:") returns the range where the string is found, and that is the only cell that is turned to bold. Set BoldRange = Range("A1:G100").Find("6. Description Summary:") 返回找到字符串的范围,这是唯一变为粗体的单元格。 Check in your code if you are not manipulting the range somewhre else where you might be changing the whole range to bold.如果您没有在其他地方操作范围,您可能会将整个范围更改为粗体,请检查您的代码。 Below the code I used, just in case it helps (just yours into a Sub()):在我使用的代码下方,以防万一它有帮助(只是你的 Sub()):

Sub FindAndBold() Set BoldRange = Range("A1:G100").Find("6. Description Summary:") If Not (BoldRange Is Nothing) Then BoldRange.Font.Bold = True End If End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM