gpt4 book ai didi

vba - Excel-VBA : Change the text color of a cell based on the text color of an adjecent cell

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

我正在开发一个循环遍历 dData 范围并识别哪些单元格具有白色字体颜色的宏。然后,它会将与 dData 相邻的任何单元格的字体颜色更改为白色。下面的代码是我到目前为止所拥有的。它还没有用,但我走在正确的轨道上吗?

谢谢!

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim dData As Range
Dim Cell As Range

Set dData = Sheets("Sheet1").Range("l2:l10000")

For Each Cell In dData
If Cell.Font.Color = 2 Then
Cell.Offset(0, -1).Font.Color = 2
End If
Next Cell
End Sub

最佳答案

这似乎对我有用。

Sub Test()
Dim dData As Range
Dim Cell As Range

Set dData = Sheets("Sheet1").Range("l2:l10000")

For Each Cell In dData.Cells
If Cell.Font.Color = 16777215 Then
Cell.offset(,1).Font.Color = 16777215
End If
Next
End Sub

注意 dData 的范围也仅限于 Sheet1

在我的电脑上,“white”是 16777215 的长值,它适用于 2010 Excel,我认为应该适用于 2007。在 Excel 2003 中我不确定。

试试这个

Sub Sample()
Dim dData As Range, aCell As Range

Set dData = Sheets("Sheet1").Range("L2:L10000")

For Each aCell In dData.Cells
If aCell.Font.ColorIndex = 2 Then _
aCell.Offset(, 1).Font.ColorIndex = 2
Next
End Sub

关于vba - Excel-VBA : Change the text color of a cell based on the text color of an adjecent cell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19297905/

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