想在excel工作表中把红色字体都改成绿色字体,vba代码怎么写啊
答案:3 悬赏:50
解决时间 2021-11-29 13:14
- 提问者网友:千城墨白
- 2021-11-28 19:19
想达到的效果是:不需要选择区域,直接触发更改,将工作表中某一颜色的字体改为另一颜色。请教大家,vba代码怎么写?
最佳答案
- 二级知识专家网友:旧事诱惑
- 2021-11-28 19:59
这个问题应该不难,只是您太过于惜字如金了。
全部回答
- 1楼网友:一池湖水
- 2021-11-28 20:26
'如果字体为红色,就改为绿色
If Range("B2").Font.ColorIndex = 3 Then Range("B2").Font.ColorIndex = 3
- 2楼网友:废途浑身病态
- 2021-11-28 20:17
字体不加粗,将.font.bold=true里的true改为false(有两处)
将f列改为其他 列,请将所有引号里的"f"改为你要的列号字母就行 (有10处)
以下是为你修改后的代码,请将第2行的"f"改为你要的列号
sub test()
const l ="f" '以后如要改到其他列,只要改这个地方
dim rng as range, rngc as range
dim introw as long
dim cntrow as long
dim cnt as long
dim n as long
dim dat()
dim stra as string
application.screenupdating = false
stra = empty
introw = range("a65536").end(xlup).row
set rng = range("a2:a" & introw)
cntrow = rng.rows.count
stra = "*" & inputbox("输入要搜索的内容") & "*"
debug.print stra
if stra = "**" then exit sub
cnt = application.worksheetfunction.countif(rng, stra)
redim dat(1 to cnt, 1 to 1)
n = 1
for each rngc in rng
if application.worksheetfunction.countif(rngc, stra) = 1 then
dat(n, 1) = rngc
n = n + 1
end if
next rngc
with range(l & "1:" & l & range(l & "65536").end(xlup).row)
.clearcontents
.clearformats
end with
range(l & "1") = "搜索结果"
with range(l & "1")
.interior.colorindex = 20
.font.name = "宋体" '这里是字体
.font.size = 12 '这里是字体大小
.font.bold = false '标题行是否加粗
.borders.linestyle = xlcontinuous
.horizontalalignment = xlcenter
end with
with range(l & "2:" & l & n)
.value = dat
.font.name = "宋体" '这里是字体
.font.size = 12 '这里是字体大小
.borders.linestyle = xlcontinuous
.font.bold = false '搜索结果是否加粗
.interior.colorindex = 19
.horizontalalignment = xlcenter
end with
range(l & "2:" & l & n).sort key1:=range(l & "2"), order1:=xlascending
msgbox (" 共 " & n - 1 & " 件被搜索.")
application.screenupdating = true
end sub
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯