gpt4 book ai didi

vba - 突出显示包含 Chr(10) 的单元格

转载 作者:行者123 更新时间:2023-12-04 22:32:00 25 4
gpt4 key购买 nike

我试图突出显示包含“Alt + Enter”(又名 Chr(10))字符的所有单元格,而不管单元格的其他内容如何。我怎样才能做到这一点?

最佳答案

这应该有效:

Sub TestForChr()

Dim rng As Range

Set rng = Application.ActiveSheet.UsedRange

For Each cell In rng
If InStr(1, cell, Chr(10)) Then
cell.Interior.ColorIndex = 3
End If
Next

End Sub

如果您想从特定的行或列开始,请使用:
Sub AnotherTestForChr()

Dim LastRow As Long, LastColumn As Long
Dim i As Long, y As Long

' LastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
' LastColumn = Sheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
LastRow = Sheets("Sheet1").UsedRange.Rows.Count
LastColumn = Sheets("Sheet1").UsedRange.Columns.Count

For i = 1 To LastRow
For y = 1 To LastColumn
If InStr(1, Cells(i, y), Chr(10)) Then
Cells(i, y).Interior.ColorIndex = 3
End If
Next
Next

End Sub

希望这可以帮助!

关于vba - 突出显示包含 Chr(10) 的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51972801/

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