答案1
答案2
虽然我不知道有任何工作表功能可以将单元格的字体颜色与其填充颜色相匹配(手动除外),但使用宏可以很容易地做到这一点。下面的第一个宏将所选范围的单元格中的字体颜色更改为与其填充颜色相匹配。第二个宏将字体颜色恢复为默认的黑色。
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
。只需用鼠标选择要修改的范围,然后选择要运行的宏即可。
答案3
好的,这是我第一次提交代码,所以开始吧。我以为宏路线是可行的,但由于您无法使用条件格式将字体设置为与单元格颜色相同,因此唯一的其他方法是使用与条件格式效果类似的宏来更改两者,如下所示:
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
希望这能对某些人有所帮助,尽管最初的问题已经晚了三年。
答案4
这是我的做法。
.Cells(RowTo, ColHcpDiP).Font.Color = .Cells(RowTo, ColHcpDiP).Interior.Color '将颜色设置为不可见