gpt4 book ai didi

excel - VBA - 如果replacement = true,则将单元格颜色更改为黄色

转载 作者:行者123 更新时间:2023-12-04 21:45:20 25 4
gpt4 key购买 nike

我正在处理一个宏,我想在下面的代码中记录一个插件:

Selection.Replace What:="<", replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
需要新代码:如果上面的代码最终替换了 <,则需要将单元格标记为黄色(colorindex=6)。哪个代码可以让我这样做?

最佳答案

您可以使用replace来替换格式

Dim ReplaceRange As Range
Set ReplaceRange = Selection

'define color for ReplaceFormat
With Application.ReplaceFormat.Interior
.ColorIndex = 6
End With
'replace the format and text
ReplaceRange.Replace What:="<", replacement:=vbEmpty, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=True, FormulaVersion:=xlReplaceFormula2

关于excel - VBA - 如果replacement = true,则将单元格颜色更改为黄色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67633478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com