Answers:
虽然我不知道有任何工作表功能可以将单元格的字体颜色与其填充颜色(手动除外)相匹配,但是使用宏非常容易。下面的第一个宏会更改选定范围的单元格中的字体颜色,以匹配其填充颜色。第二个将字体颜色恢复为默认的黑色。
Sub HideFont()
Dim cell As Variant
For Each cell In Selection
cell.Font.Color = cell.Interior.Color
Next cell
End Sub
Sub UnhideFont()
Dim cell As Variant
For Each cell In Selection
cell.Font.Color = 0
Next cell
End Sub
要安装宏,选择Developer
/ Visual Basic
从主功能区,然后选择Insert
/ Module
从菜单中。将代码粘贴到打开的编辑窗格中。通过在主功能区中选择Developer
/ Macros
,可将宏显示在可访问的宏列表中。只需使用鼠标选择要修改的范围,然后选择要运行的宏即可。
好的,这是我第一次提交代码,所以去吧。我以为可以使用宏路由,但是由于无法使用条件格式将字体设置为与单元格颜色相同,因此,唯一的其他方法是使用与条件格式的效果,请参见下文:
Sub change()
Dim Rstart, Rmid, Rend, Gstart, Gmid, Gend, Bstart, Bmid, Bend, Rsd, Rdd,_
Gsd, Gdd, Bsd, Bdd, Rcell, Gcell, Bcell As Integer
Dim maxsel, minsel, halfsel, halfval, v As Double
Rstart = 0
Rmid = 230
Rend = 255
Gstart = 0
Gmid = 230
Gend = 0
Bstart = 255
Bmid = 230
Bend = 0
Rsd = Rmid - Rstart
Rdd = Rend - Rmid
Gsd = Gmid - Gstart
Gdd = Gend - Gmid
Bsd = Bmid - Bstart
Bdd = Bend - Bmid
maxsel = Application.WorksheetFunction.Max(Selection)
minsel = Application.WorksheetFunction.Min(Selection)
halfsel = (maxsel - minsel) / 2
halfval = minsel + halfsel
If halfval = 0 Then Exit Sub
Dim cell As Variant
For Each cell In Selection
v = cell.Value
If v >= minsel And v < halfsel Then
Rcell = Round((Rstart + ((halfval - v) / halfsel) * Rsd), 0)
Gcell = Round((Gstart + ((halfval - v) / halfsel) * Gsd), 0)
Bcell = Round((Bstart + ((halfval - v) / halfsel) * Bsd), 0)
Else
Rcell = Round((Rmid + ((v - halfval) / halfsel) * Rdd), 0)
Gcell = Round((Gmid + ((v - halfval) / halfsel) * Gdd), 0)
Bcell = Round((Bmid + ((v - halfval) / halfsel) * Bdd), 0)
End If
cell.Font.Color = RGB(Rcell, Gcell, Bcell)
cell.Interior.Color = RGB(Rcell, Gcell, Bcell)
Next cell
End Sub
希望这对某人有帮助,即使对于原始问题来说已经太迟了三年。