资讯详情

VBA 行内容相同时字体变灰

📅 2026/10/11 17:07:34 | 华诺云谱 👁 阅读
VBA 行内容相同时字体变灰
1. 效果2. 实现代码Option Explicit Sub sbSameFontGrey() Dim i, j As Long Dim rng As Range Dim maxUsedRow, maxUsedCol As Long Dim ws As Worksheet: Set ws ActiveSheet On Error GoTo ErrProcess If TypeName(Selection) Range Then MsgBox Please select a cell range first!, vbExclamation Exit Sub End If Application.ScreenUpdating False maxUsedRow ws.UsedRange.Row ws.UsedRange.Rows.Count - 1 maxUsedCol ws.UsedRange.Column ws.UsedRange.Columns.Count - 1 For j Selection.Column To Selection.Column Selection.Columns.Count - 1 For i Selection.Row 1 To Selection.Row Selection.Rows.Count - 1 Set rng Cells(i, j) rng.Font.Color RGB(0, 0, 0) Color:Black If rng.Value rng.Offset(-1).Value Then rng.Font.Color RGB(217, 217, 217) Color:Grey If i maxUsedRow Then Exit For Next If j maxUsedCol Then Exit For Next Application.ScreenUpdating True Exit Sub ErrProcess: Application.ScreenUpdating True MsgBox Err.Description End Sub
📝

华诺云谱内容团队

资深建站顾问 · 行业研究员

10年+企业数字化服务经验,专注智能建站、SEO优化与品牌营销,持续输出建站技巧、行业洞察与营销干货,已帮助5000+企业实现数字化增长。

你可能需要的服务

订阅华诺云谱资讯周报

每周一封,精选建站技巧、SEO与营销干货,直达邮箱。已有 8,000+ 企业主订阅,助你少走弯路。

↑